tdisallowif.nim 564 B

1234567891011121314151617181920212223242526272829
  1. discard """
  2. errormsg: "usage of 'disallowIf' is an {.error.} defined at tdisallowif.nim(10, 1)"
  3. line: 24
  4. """
  5. template optZero{x+x}(x: int): int = x*3
  6. template andthen{`*`(x,3)}(x: int): int = x*4
  7. template optSubstr1{x = substr(x, 0, b)}(x: string, b: int) = setlen(x, b+1)
  8. template disallowIf{
  9. if cond: action
  10. else: action2
  11. }(cond: bool, action, action2: typed) {.error.} = action
  12. var y = 12
  13. echo y+y
  14. var s: array[0..2, string]
  15. s[0] = "hello"
  16. s[0] = substr(s[0], 0, 2)
  17. echo s[0]
  18. if s[0] != "hi":
  19. echo "do it"
  20. echo "more branches"
  21. else:
  22. discard