macros.newLit now works for ref object types (#12307)

This commit is contained in:
zah 2019-09-30 23:24:57 +03:00 • committed by Andreas Rumpf
commit a4ade43536
3 changed files with 33 additions and 0 deletions

View file

@ -5,6 +5,14 @@ type
a : int
b : string
RefObject = ref object
x: int
RegularObject = object
x: int
ObjectRefAlias = ref RegularObject
macro test_newLit_MyType: untyped =
let mt = MyType(a: 123, b:"foobar")
result = newLit(mt)
@ -167,3 +175,20 @@ macro test_newLit_set: untyped =
block:
let tmp: set[MyEnum] = {MyEnum.low .. MyEnum.high}
doAssert tmp == test_newLit_set
macro test_newLit_ref_object: untyped =
var x = RefObject(x: 10)
return newLit(x)
block:
let x = test_newLit_ref_object()
doAssert $(x[]) == "(x: 10)"
macro test_newLit_object_ref_alias: untyped =
var x = ObjectRefAlias(x: 10)
return newLit(x)
block:
let x = test_newLit_object_ref_alias()
doAssert $(x[]) == "(x: 10)"