From ca673ab1afb149a2f137a4c3bac06f58a8142066 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 20 Mar 2017 10:56:05 +0100 Subject: [PATCH] add test case for getAst regression --- tests/template/tgetast_typeliar.nim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/template/tgetast_typeliar.nim diff --git a/tests/template/tgetast_typeliar.nim b/tests/template/tgetast_typeliar.nim new file mode 100644 index 0000000000..c9a6125823 --- /dev/null +++ b/tests/template/tgetast_typeliar.nim @@ -0,0 +1,23 @@ + +# just ensure this keeps compiling: + +import macros + +proc error(s: string) = quit s + +macro assertOrReturn*(condition: bool; message: string): typed = + var line = condition.lineInfo() + result = quote do: + block: + if not likely(`condition`): + error("Assertion failed: " & $(`message`) & "\n" & `line`) + return + +macro assertOrReturn*(condition: bool): typed = + var message = condition.toStrLit() + result = getAst assertOrReturn(condition, message) + +proc point*(size: int16): tuple[x, y: int16] = + # returns random point in square area with given `size` + + assertOrReturn size > 0