Allow void macro result (#11286)

* allow void macro result
* add test for void macro result type
This commit is contained in:
Arne Döring 2019-05-21 21:31:40 +02:00 • committed by Andreas Rumpf
commit f94ec363ab
25 changed files with 143 additions and 60 deletions

View file

@ -18,15 +18,16 @@ case_token: inc i
#bug #488
macro foo: typed =
macro foo() =
var exp = newCall("whatwhat", newIntLitNode(1))
if compiles(getAst(exp)): return exp
if compiles(getAst(exp)):
return exp
else: echo "Does not compute! (test OK)"
foo()
#------------------------------------
# bug #8287
# bug #8287
type MyString = distinct string
proc `$` (c: MyString): string {.borrow.}
@ -37,7 +38,7 @@ proc `!!` (c: cstring): int =
proc f(name: MyString): int =
!! $ name
macro repr_and_parse(fn: typed): typed =
macro repr_and_parse(fn: typed) =
let fn_impl = fn.getImpl
fn_impl.name = genSym(nskProc, $fn_impl.name)
echo fn_impl.repr
@ -51,7 +52,7 @@ repr_and_parse(f)
#------------------------------------
# bugs #8343 and #8344
# bugs #8343 and #8344
proc one_if_proc(x, y : int): int =
if x < y: result = x
else: result = y
@ -76,7 +77,7 @@ proc test_cond_stmtlist(x, y: int): int =
#------------------------------------
# bug #8762
proc t2(a, b: int): int =
proc t2(a, b: int): int =
`+`(a, b)
@ -92,23 +93,23 @@ proc fn2(x, y: float): float =
proc fn3(x, y: int): bool =
(((x and 3) div 4) or (x mod (y xor -1))) == 0 or y notin [1,2]
proc fn4(x: int): int =
proc fn4(x: int): int =
if x mod 2 == 0: return x + 2
else: return 0
#------------------------------------
# bug #10807
proc fn_unsafeaddr(x: int): int =
proc fn_unsafeaddr(x: int): int =
cast[int](unsafeAddr(x))
static:
echo fn_unsafeaddr.repr_to_string
echo fn_unsafeaddr.repr_to_string
let fn1s = "proc fn1(x, y: int): int =\n result = 2 * (x + y)\n"
let fn2s = "proc fn2(x, y: float): float =\n result = (y + 2 * x) / (x - y)\n"
let fn3s = "proc fn3(x, y: int): bool =\n result = ((x and 3) div 4 or x mod (y xor -1)) == 0 or not contains([1, 2], y)\n"
let fn4s = "proc fn4(x: int): int =\n if x mod 2 == 0:\n return x + 2\n else:\n return 0\n"
let fnAddr = "proc fn_unsafeaddr(x: int): int =\n result = cast[int](unsafeAddr(x))\n"
doAssert fn1.repr_to_string == fn1s
doAssert fn2.repr_to_string == fn2s
doAssert fn3.repr_to_string == fn3s
@ -134,4 +135,3 @@ repr_and_parse(test_block)
repr_and_parse(test_cond_stmtlist)
repr_and_parse(t2)
repr_and_parse(test_pure_enums)