diff options
author | Saem Ghani <saemghani+github@gmail.com> | 2021-06-14 00:21:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-14 09:21:33 +0200 |
commit | 488acd9d077e8179d35d665ac0591c456bfa93aa (patch) | |
tree | 2c3d5f3dc35063b929aed0a9e9c0397fc354c4f3 /tests/macros/m18235.nim | |
parent | e1e8af535ec195e5749dffa728add95770e5cbd7 (diff) | |
download | Nim-488acd9d077e8179d35d665ac0591c456bfa93aa.tar.gz |
fixes #18235 - proc annotation type macro sym leak (#18249)
* fixes #18235 - proc annotation type macro sym leak - also fixed a typo - proc annotations guard symbol exports with shadow scopes - symbol handling is shadow scope aware * test for exporting an existing unexported sym this one is for my homie alaviss. * Special handling not needed in semProcAnnotation * Testcasing * [skip ci] clean-up and add some more comments * [skip ci] rm trailing whitespace Co-authored-by: Clyybber <darkmine956@gmail.com>
Diffstat (limited to 'tests/macros/m18235.nim')
-rw-r--r-- | tests/macros/m18235.nim | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/macros/m18235.nim b/tests/macros/m18235.nim new file mode 100644 index 000000000..6bb4547e0 --- /dev/null +++ b/tests/macros/m18235.nim @@ -0,0 +1,42 @@ +import macros + +# Necessary code to update the AST on a symbol across module boundaries when +# processed by a type macro. Used by a test of a corresponding name of this +# file. + +macro eexport(n: typed): untyped = + result = copyNimTree(n) + # turn exported nnkSym -> nnkPostfix(*, nnkIdent), forcing re-sem + result[0] = nnkPostfix.newTree(ident"*").add: + n.name.strVal.ident + +macro unexport(n: typed): untyped = + result = copyNimTree(n) + # turn nnkSym -> nnkIdent, forcing re-sem and dropping any exported-ness + # that might be present + result[0] = n.name.strVal.ident + +proc foo*() {.unexport.} = discard +proc bar() {.eexport.} = discard + +proc foooof*() {.unexport, eexport, unexport.} = discard +proc barrab() {.eexport, unexport, eexport.} = discard + +macro eexportMulti(n: typed): untyped = + # use the call version of `eexport` macro for one or more decls + result = copyNimTree(n) + for i in 0..<result.len: + result[i] = newCall(ident"eexport", result[i]) + +macro unexportMulti(n: typed): untyped = + # use the call version of `unexport` macro for one or more decls + result = copyNimTree(n) + for i in 0..<result.len: + result[i] = newCall(ident"unexport", result[i]) + +unexportMulti: + proc oof*() = discard + +eexportMulti: + proc rab() = discard + proc baz*() = discard \ No newline at end of file |