mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
retain forced open undeclared ident information (#22019)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
17
tests/lookups/tundeclaredmixin.nim
Normal file
17
tests/lookups/tundeclaredmixin.nim
Normal 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
|
||||
Reference in New Issue
Block a user