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