* 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>
This commit is contained in:
parent
e1e8af535e
commit
488acd9d07
4 changed files with 86 additions and 9 deletions
42
tests/macros/m18235.nim
Normal file
42
tests/macros/m18235.nim
Normal file
|
|
@ -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
|
||||
18
tests/macros/t18235.nim
Normal file
18
tests/macros/t18235.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import m18235
|
||||
|
||||
# this must error out because it was never actually exported
|
||||
doAssert(not declared(foo))
|
||||
doAssert not compiles(foo())
|
||||
|
||||
doAssert(not declared(foooof))
|
||||
doAssert not compiles(foooof())
|
||||
|
||||
doAssert(not declared(oof))
|
||||
doAssert not compiles(oof())
|
||||
|
||||
# this should have been exported just fine
|
||||
|
||||
bar()
|
||||
barrab()
|
||||
rab()
|
||||
baz()
|
||||
Loading…
Add table
Add a link
Reference in a new issue