tsigmatch.nim 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. discard """
  2. cmd: "nim check --showAllMismatches:on --hints:off $file"
  3. nimout: '''
  4. tsigmatch.nim(111, 4) Error: type mismatch: got <A, string>
  5. but expected one of:
  6. proc f(a: A)
  7. first type mismatch at position: 2
  8. extra argument given
  9. proc f(b: B)
  10. first type mismatch at position: 1
  11. required type for b: B
  12. but expression 'A()' is of type: A
  13. expression: f(A(), "extra")
  14. tsigmatch.nim(125, 6) Error: type mismatch: got <(string, proc (){.gcsafe, locks: 0.})>
  15. but expected one of:
  16. proc foo(x: (string, proc ()))
  17. first type mismatch at position: 1
  18. required type for x: (string, proc (){.closure.})
  19. but expression '("foobar", proc () = echo(["Hello!"]))' is of type: (string, proc (){.gcsafe, locks: 0.})
  20. expression: foo(("foobar", proc () = echo(["Hello!"])))
  21. tsigmatch.nim(132, 11) Error: type mismatch: got <proc (s: string): string{.noSideEffect, gcsafe, locks: 0.}>
  22. but expected one of:
  23. proc foo[T, S](op: proc (x: T): S {.cdecl.}): auto
  24. first type mismatch at position: 1
  25. required type for op: proc (x: T): S{.cdecl.}
  26. but expression 'fun' is of type: proc (s: string): string{.noSideEffect, gcsafe, locks: 0.}
  27. proc foo[T, S](op: proc (x: T): S {.safecall.}): auto
  28. first type mismatch at position: 1
  29. required type for op: proc (x: T): S{.safecall.}
  30. but expression 'fun' is of type: proc (s: string): string{.noSideEffect, gcsafe, locks: 0.}
  31. expression: foo(fun)
  32. tsigmatch.nim(143, 13) Error: type mismatch: got <array[0..0, proc (x: int){.gcsafe, locks: 0.}]>
  33. but expected one of:
  34. proc takesFuncs(fs: openArray[proc (x: int) {.gcsafe, locks: 0.}])
  35. first type mismatch at position: 1
  36. required type for fs: openArray[proc (x: int){.closure, gcsafe, locks: 0.}]
  37. but expression '[proc (x: int) {.gcsafe, locks: 0.} = echo [x]]' is of type: array[0..0, proc (x: int){.gcsafe, locks: 0.}]
  38. expression: takesFuncs([proc (x: int) {.gcsafe, locks: 0.} = echo [x]])
  39. tsigmatch.nim(149, 4) Error: type mismatch: got <int literal(10), a0: int literal(5), string>
  40. but expected one of:
  41. proc f(a0: uint8; b: string)
  42. first type mismatch at position: 2
  43. named param already provided: a0
  44. expression: f(10, a0 = 5, "")
  45. tsigmatch.nim(156, 4) Error: type mismatch: got <string, string, string, string, string, float64, string>
  46. but expected one of:
  47. proc f(a1: int)
  48. first type mismatch at position: 1
  49. required type for a1: int
  50. but expression '"asdf"' is of type: string
  51. proc f(a1: string; a2: varargs[string]; a3: float; a4: var string)
  52. first type mismatch at position: 7
  53. required type for a4: var string
  54. but expression '"bad"' is immutable, not 'var'
  55. expression: f("asdf", "1", "2", "3", "4", 2.3, "bad")
  56. tsigmatch.nim(164, 4) Error: type mismatch: got <string, a0: int literal(12)>
  57. but expected one of:
  58. proc f(x: string; a0: string)
  59. first type mismatch at position: 2
  60. required type for a0: string
  61. but expression 'a0 = 12' is of type: int literal(12)
  62. proc f(x: string; a0: var int)
  63. first type mismatch at position: 2
  64. required type for a0: var int
  65. but expression 'a0 = 12' is immutable, not 'var'
  66. expression: f(foo, a0 = 12)
  67. tsigmatch.nim(171, 7) Error: type mismatch: got <Mystring, string>
  68. but expected one of:
  69. proc fun1(a1: MyInt; a2: Mystring)
  70. first type mismatch at position: 1
  71. required type for a1: MyInt
  72. but expression 'default(Mystring)' is of type: Mystring
  73. proc fun1(a1: float; a2: Mystring)
  74. first type mismatch at position: 1
  75. required type for a1: float
  76. but expression 'default(Mystring)' is of type: Mystring
  77. expression: fun1(default(Mystring), "asdf")
  78. '''
  79. errormsg: "type mismatch"
  80. """
  81. ## line 100
  82. when true:
  83. # bug #11061 Type mismatch error "first type mismatch at" points to wrong argument/position
  84. # Note: the error msg now gives correct position for mismatched argument
  85. type
  86. A = object of RootObj
  87. B = object of A
  88. block:
  89. proc f(b: B) = discard
  90. proc f(a: A) = discard
  91. f(A(), "extra")
  92. #[
  93. this one is similar but error msg was even more misleading, since the user
  94. would think float != float64 where in fact the issue is another param:
  95. first type mismatch at position: 1; required type: float; but expression 'x = 1.2' is of type: float64
  96. proc f(x: string, a0 = 0, a1 = 0, a2 = 0) = discard
  97. proc f(x: float, a0 = 0, a1 = 0, a2 = 0) = discard
  98. f(x = float(1.2), a0 = 0, a0 = 0)
  99. ]#
  100. block:
  101. # bug #7808 Passing tuple with proc leads to confusing errors
  102. # Note: the error message now shows `closure` which helps debugging the issue
  103. proc foo(x: (string, proc ())) = x[1]()
  104. foo(("foobar", proc () = echo("Hello!")))
  105. block:
  106. # bug #8305 type mismatch error drops crucial pragma info when there's only 1 argument
  107. proc fun(s: string): string {. .} = discard
  108. proc foo[T, S](op: proc (x: T): S {. cdecl .}): auto = 1
  109. proc foo[T, S](op: proc (x: T): S {. safecall .}): auto = 1
  110. echo foo(fun)
  111. block:
  112. # bug #10285 Function signature don't match when inside seq/array/openarray
  113. # Note: the error message now shows `closure` which helps debugging the issue
  114. # out why it doesn't match
  115. proc takesFunc(f: proc (x: int) {.gcsafe, locks: 0.}) =
  116. echo "takes single Func"
  117. proc takesFuncs(fs: openarray[proc (x: int) {.gcsafe, locks: 0.}]) =
  118. echo "takes multiple Func"
  119. takesFunc(proc (x: int) {.gcsafe, locks: 0.} = echo x) # works
  120. takesFuncs([proc (x: int) {.gcsafe, locks: 0.} = echo x]) # fails
  121. block:
  122. # bug https://github.com/nim-lang/Nim/issues/11061#issuecomment-508970465
  123. # better fix for removal of `errCannotBindXTwice` due to #3836
  124. proc f(a0: uint8, b: string) = discard
  125. f(10, a0 = 5, "")
  126. block:
  127. # bug: https://github.com/nim-lang/Nim/issues/11061#issuecomment-508969796
  128. # sigmatch gets confused with param/arg position after varargs
  129. proc f(a1: int) = discard
  130. proc f(a1: string, a2: varargs[string], a3: float, a4: var string) = discard
  131. f("asdf", "1", "2", "3", "4", 2.3, "bad")
  132. block:
  133. # bug: https://github.com/nim-lang/Nim/issues/11061#issuecomment-508970046
  134. # err msg incorrectly said something is immutable
  135. proc f(x: string, a0: var int) = discard
  136. proc f(x: string, a0: string) = discard
  137. var foo = ""
  138. f(foo, a0 = 12)
  139. when true:
  140. type Mystring = string
  141. type MyInt = int
  142. proc fun1(a1: MyInt, a2: Mystring) = discard
  143. proc fun1(a1: float, a2: Mystring) = discard
  144. fun1(Mystring.default, "asdf")