Skip to content

Commit

Permalink
walk back some functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Sep 29, 2023
1 parent 6a9e312 commit e194df3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 43 deletions.
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ proc semSymChoice(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: P
# some contexts might want sym choices preserved for later disambiguation
# in general though they are ambiguous
let first = n[0]
if nfPreferredSym in first.flags:
if result.len == 1 or nfPreferredSym in first.flags:
result = first
else:
var err = "ambiguous identifier '" & first.sym.name.s &
Expand Down
5 changes: 5 additions & 0 deletions compiler/semgnrc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym,
template maybeDotChoice(c: PContext, n: PNode, s: PSym, fromDotExpr: bool) =
if fromDotExpr:
result = symChoice(c, n, s, scForceOpen)
if result.kind == nkOpenSymChoice and result.len == 1:
result.transitionSonsKind(nkClosedSymChoice)
else:
result = symChoice(c, n, s, scOpen)
if withinMixin in flags and result.kind == nkSym:
result.flags.incl nfOpenSym
result.typ = nil
case s.kind
of skUnknown:
# Introduced in this pass! Leave it as an identifier.
Expand Down
2 changes: 1 addition & 1 deletion compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ proc track(tracked: PEffects, n: PNode) =
if n.sym.typ != nil and tfHasAsgn in n.sym.typ.flags:
tracked.owner.flags.incl sfInjectDestructors
# bug #15038: ensure consistency
if not hasDestructor(n.typ) and sameType(n.typ, n.sym.typ): n.typ = n.sym.typ
if n.typ != nil and not hasDestructor(n.typ) and sameType(n.typ, n.sym.typ): n.typ = n.sym.typ
of nkHiddenAddr, nkAddr:
if n[0].kind == nkSym and isLocalSym(tracked, n[0].sym):
useVarNoInitCheck(tracked, n[0], n[0].sym)
Expand Down
23 changes: 6 additions & 17 deletions compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule;
markUsed(c, info, s)
onUse(info, s)
else:
if s.kind in routineKinds:
result.flags.incl nfPreferredSym
else:
result.flags.incl nfOpenSym
result.typ = nil
# could maybe instead generate a open symchoice with a preferred sym,
# which the logic for is in the top else branch
result.flags.incl nfPreferredSym
incl(s.flags, sfUsed)
markOwnerModuleAsUsed(c, s)
else:
Expand Down Expand Up @@ -256,24 +254,15 @@ proc semTemplSymbol(c: PContext, n: PNode, s: PSym; isField: bool): PNode =
result.typ = nil
of skGenericParam:
if isField and sfGenSym in s.flags: result = n
else:
result = newSymNodeTypeDesc(s, c.idgen, n.info)
result.flags.incl nfOpenSym
result.typ = nil
else: result = newSymNodeTypeDesc(s, c.idgen, n.info)
of skParam:
result = n
of skType:
if isField and sfGenSym in s.flags: result = n
else:
result = newSymNodeTypeDesc(s, c.idgen, n.info)
result.flags.incl nfOpenSym
result.typ = nil
else: result = newSymNodeTypeDesc(s, c.idgen, n.info)
else:
if isField and sfGenSym in s.flags: result = n
else:
result = newSymNode(s, n.info)
result.flags.incl nfOpenSym
result.typ = nil
else: result = newSymNode(s, n.info)
# Issue #12832
when defined(nimsuggest):
suggestSym(c.graph, n.info, s, c.graph.usageSym, false)
Expand Down
15 changes: 1 addition & 14 deletions tests/lookups/topensym.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ block: # issue #22605, normal call syntax

doAssert g(int) == "good"

block: # issu #22605, method call syntax
block: # issue #22605, method call syntax
const error = "bad"

template valueOr(self: int, def: untyped): untyped =
Expand All @@ -34,19 +34,6 @@ block: # issu #22605, method call syntax

doAssert g(int) == "good"

block: # issue #22605, template case
template valueOr(self, def: untyped): untyped =
block:
template error: untyped {.used, inject.} = "good"
def

const error = "bad"
template g: untyped =
let x = 123.valueOr:
$error
x
doAssert g == "good"

block: # issue #22605, original complex example
type Xxx = enum
error
Expand Down
11 changes: 1 addition & 10 deletions tests/template/tinnerouterproc.nim
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
block: # issue #20002
block: # #20002
proc bar(x: int): int = 10
template foo =
proc bar(x: int): int {.gensym.} = x + 2
doAssert bar(3) == 5
discard 3.bar # evaluates to 10 but only check if it compiles for now
block:
foo()

block: # issue #20000, no gensym
proc bar(x: int): int = 10
template foo =
proc bar(x: int): int = x + 2
doAssert bar(3) == 5
doAssert 3.bar == 5
block:
foo()

0 comments on commit e194df3

Please sign in to comment.