diff options
author | metagn <metagngn@gmail.com> | 2022-08-23 22:41:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-23 21:41:30 +0200 |
commit | d1d141b135a605f81935e89322549013e5be3863 (patch) | |
tree | 27d0552df431ffa940ba8f66dc4be5507de2ad8d /tests/template/tredefinition_override.nim | |
parent | 14656154efa2b3f08a341742c697fd1064f40166 (diff) | |
download | Nim-d1d141b135a605f81935e89322549013e5be3863.tar.gz |
new .redefine pragma for templates, warn on redefinition without it (#20211)
* test CI for template redefinitions * adapt asyncmacro * fix quote * fix again * try something else * revert * fix ioselectors_select, disable packages CI * adapt more tests & simplify * more * more * more * rename to redefine, warn on implicit redefinition * basic documentation [skip ci] * Update compiler/lineinfos.nim Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
Diffstat (limited to 'tests/template/tredefinition_override.nim')
-rw-r--r-- | tests/template/tredefinition_override.nim | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/template/tredefinition_override.nim b/tests/template/tredefinition_override.nim new file mode 100644 index 000000000..0bda4025b --- /dev/null +++ b/tests/template/tredefinition_override.nim @@ -0,0 +1,33 @@ +{.push warningAsError[TemplateRedefinition]: on.} + +doAssert not (compiles do: + template foo(): int = 1 + template foo(): int = 2) +doAssert (compiles do: + template foo(): int = 1 + template foo(): int {.redefine.} = 2) +doAssert not (compiles do: + block: + template foo() = + template bar: string {.gensym.} = "a" + template bar: string {.gensym.} = "b" + foo()) +doAssert (compiles do: + block: + template foo() = + template bar: string {.gensym.} = "a" + template bar: string {.gensym, redefine.} = "b" + foo()) + +block: + template foo(): int = 1 + template foo(): int {.redefine.} = 2 + doAssert foo() == 2 +block: + template foo(): string = + template bar: string {.gensym.} = "a" + template bar: string {.gensym, redefine.} = "b" + bar() + doAssert foo() == "b" + +{.pop.} |