t8741.nim 636 B

123456789101112131415161718192021222324252627282930
  1. discard """
  2. cmd: "nim check --hint:processing:off $file"
  3. errormsg: "3 is not two"
  4. nimout: '''t8741.nim(13, 9) Error: cannot attach a custom pragma to 'a'
  5. t8741.nim(29, 15) template/generic instantiation of `onlyTwo` from here
  6. t8741.nim(25, 12) Error: 3 is not two
  7. '''
  8. """
  9. for a {.gensym, inject.} in @[1,2,3]:
  10. discard
  11. for a {.foobar.} in @[1,2,3]:
  12. discard
  13. type Foo[N: static[int]] = distinct int
  14. proc isTwo(n: int): bool =
  15. n == 2
  16. proc onlyTwo[N: static[int]](a: Foo[N]): int =
  17. when isTwo(N):
  18. int(a)
  19. else:
  20. {.error: $(N) & " is not two".}
  21. when isMainModule:
  22. let foo: Foo[3] = Foo[3](5)
  23. echo onlyTwo(foo)