new gensym handling (#11985)
* new .gensym implementation * make astspec test green again * introduce a --useVersion switch to group compatibility switches * fixes #10180 * fixes #11494 * fixes #11483 * object constructor fields and named parameters are also not gensym'ed * disabled broken package
This commit is contained in:
parent
f28a47ea7b
commit
b07694cd90
18 changed files with 346 additions and 114 deletions
44
tests/template/tmore_regressions.nim
Normal file
44
tests/template/tmore_regressions.nim
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
discard """
|
||||
output: '''0
|
||||
|
||||
0.0'''
|
||||
"""
|
||||
|
||||
# bug #11494
|
||||
import macros
|
||||
|
||||
macro staticForEach(arr: untyped, body: untyped): untyped =
|
||||
result = newNimNode(nnkStmtList)
|
||||
|
||||
arr.expectKind(nnkBracket)
|
||||
for n in arr:
|
||||
let b = copyNimTree(body)
|
||||
result.add quote do:
|
||||
block:
|
||||
type it {.inject.} = `n`
|
||||
`b`
|
||||
|
||||
template forEveryMatchingEntity*() =
|
||||
staticForEach([int, string, float]):
|
||||
var a: it
|
||||
echo a
|
||||
|
||||
forEveryMatchingEntity()
|
||||
|
||||
|
||||
# bug #11483
|
||||
proc main =
|
||||
template first(body) =
|
||||
template second: var int =
|
||||
var o: int
|
||||
var i = addr(o)
|
||||
i[]
|
||||
|
||||
body
|
||||
|
||||
first:
|
||||
second = 5
|
||||
second = 6
|
||||
|
||||
main()
|
||||
|
||||
|
|
@ -8,6 +8,7 @@ output: '''
|
|||
1
|
||||
2
|
||||
3
|
||||
wth
|
||||
'''
|
||||
"""
|
||||
# bug #1915
|
||||
|
|
@ -130,3 +131,17 @@ template test() =
|
|||
doAssert(foo.len == 3)
|
||||
|
||||
test()
|
||||
|
||||
# regression found in PMunch's parser generator
|
||||
|
||||
proc namedcall(arg: string) =
|
||||
discard
|
||||
|
||||
macro m(): untyped =
|
||||
result = quote do:
|
||||
(proc (arg: string) =
|
||||
namedcall(arg = arg)
|
||||
echo arg)
|
||||
|
||||
let meh = m()
|
||||
meh("wth")
|
||||
|
|
|
|||
13
tests/template/tredefinition.nim
Normal file
13
tests/template/tredefinition.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
discard """
|
||||
errormsg: "redefinition of 'a`gensym"
|
||||
line: 9
|
||||
"""
|
||||
# bug #10180
|
||||
proc f() =
|
||||
template t() =
|
||||
var a = 1
|
||||
var a = 2
|
||||
echo a
|
||||
t()
|
||||
|
||||
f()
|
||||
Loading…
Add table
Add a link
Reference in a new issue