Skip to content

Commit ed263e1

Browse files
authored
fix #13524 astToStr now works inside generics (#13681)
1 parent a870623 commit ed263e1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/semgnrc.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ proc semGenericStmt(c: PContext, n: PNode,
226226
var mixinContext = false
227227
if s != nil:
228228
incl(s.flags, sfUsed)
229-
mixinContext = s.magic in {mDefined, mDefinedInScope, mCompiles}
229+
mixinContext = s.magic in {mDefined, mDefinedInScope, mCompiles, mAstToStr}
230230
let sc = symChoice(c, fn, s, if s.isMixedIn: scForceOpen else: scOpen)
231231
case s.kind
232232
of skMacro:

tests/generics/t13525.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# https://github.com/nim-lang/Nim/issues/13524
2+
template fun(field): untyped = astToStr(field)
3+
proc test1(): string = fun(nonexistant1)
4+
proc test2[T](): string = fun(nonexistant2) # used to cause: Error: undeclared identifier: 'nonexistant2'
5+
doAssert test1() == "nonexistant1"
6+
doAssert test2[int]() == "nonexistant2"

0 commit comments

Comments
 (0)