retain forced open undeclared ident information (#22019)

This commit is contained in:
metagn
2023-06-07 12:36:51 +03:00
committed by GitHub
parent fcc383d899
commit ce72b564bc
3 changed files with 21 additions and 5 deletions

View File

@@ -64,7 +64,7 @@ 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.len == 1:
if result.kind == nkOpenSymChoice and result.len == 1:
result.transitionSonsKind(nkClosedSymChoice)
else:
result = symChoice(c, n, s, scOpen)

View File

@@ -70,6 +70,9 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule;
onUse(info, s)
else:
result = n
elif i == 0:
# forced open but symbol not in scope, retain information
result = n
else:
# semantic checking requires a type; ``fitNode`` deals with it
# appropriately
@@ -110,14 +113,10 @@ proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
proc semMixinStmt(c: PContext, n: PNode, toMixin: var IntSet): PNode =
result = copyNode(n)
var count = 0
for i in 0..<n.len:
toMixin.incl(considerQuotedIdent(c, n[i]).id)
let x = symChoice(c, n[i], nil, scForceOpen)
inc count, x.len
result.add x
if count == 0:
result = newNodeI(nkEmpty, n.info)
proc replaceIdentBySym(c: PContext; n: var PNode, s: PNode) =
case n.kind

View File

@@ -0,0 +1,17 @@
discard """
nimout: '''
mixin nothing, add
'''
"""
# issue #22012
import macros
expandMacros:
proc foo[T](): int =
# `nothing` is undeclared, `add` is declared
mixin nothing, add
123
doAssert foo[int]() == 123