diff options
Diffstat (limited to 'tests/reject/tdisallowif.nim')
-rw-r--r-- | tests/reject/tdisallowif.nim | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/reject/tdisallowif.nim b/tests/reject/tdisallowif.nim new file mode 100644 index 000000000..002bc7491 --- /dev/null +++ b/tests/reject/tdisallowif.nim @@ -0,0 +1,28 @@ +discard """ + line: 24 + errormsg: "usage of 'disallowIf' is a user-defined error" +""" + +template optZero{x+x}(x: int): int = x*3 +template andthen{x*3}(x: int): int = x*4 +template optSubstr1{x = substr(x, a, b)}(x: string, a, b: int) = setlen(x, b+1) + +template disallowIf{ + if cond: action + else: action2 +}(cond: bool, action, action2: stmt) {.error.} = action + +var y = 12 +echo y+y + +var s: array[0..2, string] +s[0] = "hello" +s[0] = substr(s[0], 0, 2) + +echo s[0] + +if true: + echo "do it" + echo "more branches" +else: + nil |