tsigmatch.nim 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. discard """
  2. cmd: "nim check --mm:refc --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.})>
  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.})
  20. expression: foo(("foobar", proc () = echo(["Hello!"])))
  21. tsigmatch.nim(132, 11) Error: type mismatch: got <proc (s: string): string{.noSideEffect, gcsafe.}>
  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.}
  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.}
  31. expression: foo(fun)
  32. tsigmatch.nim(143, 13) Error: type mismatch: got <array[0..0, proc (x: int){.gcsafe.}]>
  33. but expected one of:
  34. proc takesFuncs(fs: openArray[proc (x: int) {.gcsafe.}])
  35. first type mismatch at position: 1
  36. required type for fs: openArray[proc (x: int){.closure, gcsafe.}]
  37. but expression '[proc (x: int) {.gcsafe.} = echo [x]]' is of type: array[0..0, proc (x: int){.gcsafe.}]
  38. expression: takesFuncs([proc (x: int) {.gcsafe.} = 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. #[
  82. see also: tests/errmsgs/tdeclaredlocs.nim
  83. ]#
  84. ## line 100
  85. when true:
  86. # bug #11061 Type mismatch error "first type mismatch at" points to wrong argument/position
  87. # Note: the error msg now gives correct position for mismatched argument
  88. type
  89. A = object of RootObj
  90. B = object of A
  91. block:
  92. proc f(b: B) = discard
  93. proc f(a: A) = discard
  94. f(A(), "extra")
  95. #[
  96. this one is similar but error msg was even more misleading, since the user
  97. would think float != float64 where in fact the issue is another param:
  98. first type mismatch at position: 1; required type: float; but expression 'x = 1.2' is of type: float64
  99. proc f(x: string, a0 = 0, a1 = 0, a2 = 0) = discard
  100. proc f(x: float, a0 = 0, a1 = 0, a2 = 0) = discard
  101. f(x = float(1.2), a0 = 0, a0 = 0)
  102. ]#
  103. block:
  104. # bug #7808 Passing tuple with proc leads to confusing errors
  105. # Note: the error message now shows `closure` which helps debugging the issue
  106. proc foo(x: (string, proc ())) = x[1]()
  107. foo(("foobar", proc () = echo("Hello!")))
  108. block:
  109. # bug #8305 type mismatch error drops crucial pragma info when there's only 1 argument
  110. proc fun(s: string): string {. .} = discard
  111. proc foo[T, S](op: proc (x: T): S {. cdecl .}): auto = 1
  112. proc foo[T, S](op: proc (x: T): S {. safecall .}): auto = 1
  113. echo foo(fun)
  114. block:
  115. # bug #10285 Function signature don't match when inside seq/array/openArray
  116. # Note: the error message now shows `closure` which helps debugging the issue
  117. # out why it doesn't match
  118. proc takesFunc(f: proc (x: int) {.gcsafe.}) =
  119. echo "takes single Func"
  120. proc takesFuncs(fs: openArray[proc (x: int) {.gcsafe.}]) =
  121. echo "takes multiple Func"
  122. takesFunc(proc (x: int) {.gcsafe.} = echo x) # works
  123. takesFuncs([proc (x: int) {.gcsafe.} = echo x]) # fails
  124. block:
  125. # bug https://github.com/nim-lang/Nim/issues/11061#issuecomment-508970465
  126. # better fix for removal of `errCannotBindXTwice` due to #3836
  127. proc f(a0: uint8, b: string) = discard
  128. f(10, a0 = 5, "")
  129. block:
  130. # bug: https://github.com/nim-lang/Nim/issues/11061#issuecomment-508969796
  131. # sigmatch gets confused with param/arg position after varargs
  132. proc f(a1: int) = discard
  133. proc f(a1: string, a2: varargs[string], a3: float, a4: var string) = discard
  134. f("asdf", "1", "2", "3", "4", 2.3, "bad")
  135. block:
  136. # bug: https://github.com/nim-lang/Nim/issues/11061#issuecomment-508970046
  137. # err msg incorrectly said something is immutable
  138. proc f(x: string, a0: var int) = discard
  139. proc f(x: string, a0: string) = discard
  140. var foo = ""
  141. f(foo, a0 = 12)
  142. when true:
  143. type Mystring = string
  144. type MyInt = int
  145. proc fun1(a1: MyInt, a2: Mystring) = discard
  146. proc fun1(a1: float, a2: Mystring) = discard
  147. fun1(Mystring.default, "asdf")