terrmsgs.nim 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. discard """
  2. action: reject
  3. cmd: '''nim check $options $file'''
  4. matrix: "; -d:testWithout"
  5. """
  6. when not defined(testWithout): # test for same errors before and after
  7. {.experimental: "dotOperators".}
  8. {.experimental: "callOperator".}
  9. # issue #13063
  10. block:
  11. type Foo = object
  12. type Bar = object
  13. x1: int
  14. var b: Bar
  15. block:
  16. template `.`(a: Foo, b: untyped): untyped = 123
  17. echo b.x #[tt.Error
  18. ^ undeclared field: 'x' for type terrmsgs.Bar [type declared in terrmsgs.nim(15, 8)]]#
  19. block:
  20. template `.()`(a: Foo, b: untyped): untyped = 123
  21. echo b.x() #[tt.Error
  22. ^ attempting to call undeclared routine: 'x']#
  23. block:
  24. template `.=`(a: Foo, b: untyped, c: untyped) = b = c
  25. b.x = 123 #[tt.Error
  26. ^ undeclared field: 'x=' for type terrmsgs.Bar [type declared in terrmsgs.nim(15, 8)]]#
  27. # yeah it says x= but does it matter in practice
  28. block:
  29. template `()`(a: Foo, b: untyped, c: untyped) = echo "something"
  30. # completely undeclared::
  31. xyz(123) #[tt.Error
  32. ^ undeclared identifier: 'xyz']#
  33. # already declared routine:
  34. min(123) #[tt.Error
  35. ^ type mismatch: got <int literal(123)>]#
  36. # non-routine type shows `()` overloads:
  37. b(123) #[tt.Error
  38. ^ attempting to call routine: 'b']#
  39. echo b.x #[tt.Error
  40. ^ undeclared field: 'x' for type terrmsgs.Bar [type declared in terrmsgs.nim(15, 8)]]#
  41. echo b.x() #[tt.Error
  42. ^ attempting to call undeclared routine: 'x']#
  43. # issue #7777
  44. import macros
  45. block:
  46. type TestType = object
  47. private_field: string
  48. when false:
  49. template getField(obj, field: untyped): untyped = obj.field
  50. macro `.`(obj: TestType, field: untyped): untyped =
  51. let private = newIdentNode("private_" & $field)
  52. result = quote do:
  53. `obj`.getField(`private`) #[tt.Error
  54. ^ attempting to call undeclared routine: 'getField']#
  55. var tt: TestType
  56. discard tt.field
  57. block: # related to issue #6981
  58. proc `()`(a:string, b:string):string = a & b
  59. proc mewSeq[T](a,b:int)=discard
  60. proc mewSeq[T](c:int)= discard
  61. mewSeq[int]() #[tt.Error
  62. ^ type mismatch: got <>]#