From ed263e174e7f9a7bce1863dc57979c1a752d2e66 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 18 Mar 2020 05:43:32 -0700 Subject: fix #13524 astToStr now works inside generics (#13681) --- compiler/semgnrc.nim | 2 +- tests/generics/t13525.nim | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/generics/t13525.nim diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index a494db475..6fefc2233 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -226,7 +226,7 @@ proc semGenericStmt(c: PContext, n: PNode, var mixinContext = false if s != nil: incl(s.flags, sfUsed) - mixinContext = s.magic in {mDefined, mDefinedInScope, mCompiles} + mixinContext = s.magic in {mDefined, mDefinedInScope, mCompiles, mAstToStr} let sc = symChoice(c, fn, s, if s.isMixedIn: scForceOpen else: scOpen) case s.kind of skMacro: diff --git a/tests/generics/t13525.nim b/tests/generics/t13525.nim new file mode 100644 index 000000000..d1b8df78c --- /dev/null +++ b/tests/generics/t13525.nim @@ -0,0 +1,6 @@ +# https://github.com/nim-lang/Nim/issues/13524 +template fun(field): untyped = astToStr(field) +proc test1(): string = fun(nonexistant1) +proc test2[T](): string = fun(nonexistant2) # used to cause: Error: undeclared identifier: 'nonexistant2' +doAssert test1() == "nonexistant1" +doAssert test2[int]() == "nonexistant2" -- cgit 1.4.1-2-gfad0