diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-08-11 03:17:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-11 12:17:17 +0200 |
commit | 6c1bd4bb1cb7a6af38b5929fe02b069b03e39db4 (patch) | |
tree | 526b758f8fb41d6e3d86c6f71ae1018ed6bd2529 /tests/pragmas | |
parent | 854006575498704c42b5ac465fdc74c3efdb5b97 (diff) | |
download | Nim-6c1bd4bb1cb7a6af38b5929fe02b069b03e39db4.tar.gz |
fix: `var a{.foo.} = expr` inside templates (refs #15920) (except when `foo` is overloaded) (#13869)
* fix: `var a{.foo.} = expr` inside templates * add test * improve tdecls test * improve tests * add failing test * PRTEMP * fixup
Diffstat (limited to 'tests/pragmas')
-rw-r--r-- | tests/pragmas/tpragmas_misc.nim | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/pragmas/tpragmas_misc.nim b/tests/pragmas/tpragmas_misc.nim index 247fa471e..8cab74053 100644 --- a/tests/pragmas/tpragmas_misc.nim +++ b/tests/pragmas/tpragmas_misc.nim @@ -10,3 +10,55 @@ block: static: doAssert defined(tpragmas_misc_def) {.undef(tpragmas_misc_def).} static: doAssert not defined(tpragmas_misc_def) + +block: # (partial fix) bug #15920 + block: # var template pragmas don't work in templates + template foo(lhs, typ, expr) = + let lhs = expr + proc fun1()= + let a {.foo.} = 1 + template fun2()= + let a {.foo.} = 1 + fun1() # ok + fun2() # WAS bug + + template foo2() = discard # distractor (template or other symbol kind) + block: + template foo2(lhs, typ, expr) = + let lhs = expr + proc fun1()= + let a {.foo2.} = 1 + template fun2()= + let a {.foo2.} = 1 + fun1() # ok + when false: # bug: Error: invalid pragma: foo2 + fun2() + + block: # proc template pragmas don't work in templates + # adapted from $nim/lib/std/private/since.nim + # case without overload + template since3(version: (int, int), body: untyped) {.dirty.} = + when (NimMajor, NimMinor) >= version: + body + when false: # bug + template fun3(): int {.since3: (1, 3).} = 12 + + block: # ditto, w + # case with overload + template since2(version: (int, int), body: untyped) {.dirty.} = + when (NimMajor, NimMinor) >= version: + body + template since2(version: (int, int, int), body: untyped) {.dirty.} = + when (NimMajor, NimMinor, NimPatch) >= version: + body + when false: # bug + template fun3(): int {.since2: (1, 3).} = 12 + +when true: # D20210801T100514:here + from macros import genSym + block: + template fn() = + var ret {.gensym.}: int # must special case template pragmas so it doesn't get confused + discard ret + fn() + static: discard genSym() |