tuntypedoverload.nim 1017 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. discard """
  2. cmd: "nim check $file"
  3. """
  4. block:
  5. template foo(x: var int, y: untyped) = discard
  6. var a: float
  7. foo(a, undeclared) #[tt.Error
  8. ^ type mismatch: got <float, untyped>]# # `untyped` is arbitary
  9. # previous error: undeclared identifier: 'undeclared'
  10. block: # issue #8697
  11. type
  12. Fruit = enum
  13. apple
  14. banana
  15. orange
  16. macro hello(x, y: untyped) = discard
  17. hello(apple, banana, orange) #[tt.Error
  18. ^ type mismatch: got <Fruit, Fruit, Fruit>]#
  19. block: # issue #23265
  20. template declareFoo(fooName: untyped, value: uint16) =
  21. const `fooName Value` {.inject.} = value
  22. declareFoo(FOO, 0xFFFF)
  23. declareFoo(BAR, 0xFFFFF) #[tt.Error
  24. ^ type mismatch: got <untyped, int literal(1048575)>]#
  25. block: # issue #9620
  26. template forLoop(index: untyped, length: int{lvalue}, body: untyped) =
  27. for `index`{.inject.} in 0 ..< length:
  28. body
  29. var x = newSeq[int](10)
  30. forLoop(i, x.len): #[tt.Error
  31. ^ type mismatch: got <untyped, int, void>]#
  32. x[i] = i