tdisallowif.nim 554 B

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