Nim/tests/macros/tescape_var_into_quotedo_as_const.nim
2018-12-05 10:58:18 +01:00

36 lines
540 B
Nim

discard """
output: '''ok'''
"""
# bug #9864
import macros, tables
proc bar(shOpt: Table[string, int]) = discard
macro dispatchGen(): untyped =
var shOpt = initTable[string, int]()
shOpt["foo"] = 10
result = quote do:
bar(`shOpt`)
dispatchGen()
type
Foo = object
data: seq[int]
proc barB(a: Foo) = discard
proc shOptB(): auto =
var shOpt: Foo
shOpt.data.setLen 1 # fails
shOpt
macro dispatchGenB(): untyped =
var shOpt = shOptB() # fails
result = quote do:
barB(`shOpt`)
dispatchGenB()
echo "ok"