diff options
Diffstat (limited to 'tests/errmsgs')
115 files changed, 1960 insertions, 66 deletions
diff --git a/tests/errmsgs/m8794.nim b/tests/errmsgs/m8794.nim new file mode 100644 index 000000000..12e61cf54 --- /dev/null +++ b/tests/errmsgs/m8794.nim @@ -0,0 +1,2 @@ +type Foo3* = object + a1: int diff --git a/tests/errmsgs/mambparam1.nim b/tests/errmsgs/mambparam1.nim new file mode 100644 index 000000000..1a5133c3c --- /dev/null +++ b/tests/errmsgs/mambparam1.nim @@ -0,0 +1 @@ +const test* = "foo" diff --git a/tests/errmsgs/mambparam2.nim b/tests/errmsgs/mambparam2.nim new file mode 100644 index 000000000..073e3f8c8 --- /dev/null +++ b/tests/errmsgs/mambparam2.nim @@ -0,0 +1,2 @@ +import mambparam1 +export test diff --git a/tests/errmsgs/mambparam3.nim b/tests/errmsgs/mambparam3.nim new file mode 100644 index 000000000..5469244e2 --- /dev/null +++ b/tests/errmsgs/mambparam3.nim @@ -0,0 +1 @@ +const test* = "bar" diff --git a/tests/errmsgs/mb.nim b/tests/errmsgs/mb.nim new file mode 100644 index 000000000..2d21e2396 --- /dev/null +++ b/tests/errmsgs/mb.nim @@ -0,0 +1,2 @@ +type + typ* = distinct string diff --git a/tests/errmsgs/mc.nim b/tests/errmsgs/mc.nim new file mode 100644 index 000000000..79d7431df --- /dev/null +++ b/tests/errmsgs/mc.nim @@ -0,0 +1,3 @@ + +type + typ* = distinct int diff --git a/tests/errmsgs/t10251.nim b/tests/errmsgs/t10251.nim new file mode 100644 index 000000000..19adf02eb --- /dev/null +++ b/tests/errmsgs/t10251.nim @@ -0,0 +1,19 @@ +discard """ + action:reject + cmd: "nim check $options $file" + nimout: ''' +t10251.nim(19, 23) Error: redefinition of 'goo1'; previous declaration here: t10251.nim(19, 11) +''' +""" + +# line 10 +type + Enum1 = enum + foo, bar, baz + Enum2 = enum + foo, bar, baz + + +type + Enum3 {.pure.} = enum # fixed (by accident?) in https://github.com/nim-lang/Nim/pull/18263 + goo0, goo1, goo2, goo1 diff --git a/tests/errmsgs/t10376.nim b/tests/errmsgs/t10376.nim new file mode 100644 index 000000000..814c860dc --- /dev/null +++ b/tests/errmsgs/t10376.nim @@ -0,0 +1,32 @@ +discard """ + matrix: "--mm:refc" + errormsg: "finalizer must be a direct reference to a proc" + line: 30 +""" + +type + A = ref object + +proc my_callback(a: A) {. nimcall .} = + discard + +proc foo(callback: proc(a: A) {. nimcall .}) = + var x1: A + new(x1, proc (x: A) {.nimcall.} = discard) + var x2: A + new(x2, func (x: A) {.nimcall.} = discard) + + var x3: A + proc foo1(a: A) {.nimcall.} = discard + new(x3, foo1) + var x4: A + func foo2(a: A) {.nimcall.} = discard + new(x4, foo2) + + var x5: A + new(x5, my_callback) + + var x6: A + new(x6, callback) + +foo(my_callback) diff --git a/tests/errmsgs/t10489_a.nim b/tests/errmsgs/t10489_a.nim new file mode 100644 index 000000000..c762ce876 --- /dev/null +++ b/tests/errmsgs/t10489_a.nim @@ -0,0 +1,9 @@ +discard """ +errormsg: "invalid type: 'macro (body: untyped): untyped{.noSideEffect, gcsafe.}' for let. Did you mean to call the macro with '()'?" +line: 9 +""" + +macro m(body: untyped): untyped = + body + +let x1 = m diff --git a/tests/errmsgs/t10489_b.nim b/tests/errmsgs/t10489_b.nim new file mode 100644 index 000000000..df05f0e6e --- /dev/null +++ b/tests/errmsgs/t10489_b.nim @@ -0,0 +1,9 @@ +discard """ +errormsg: "invalid type: 'macro (body: untyped): untyped{.noSideEffect, gcsafe.}' for const. Did you mean to call the macro with '()'?" +line: 9 +""" + +macro m(body: untyped): untyped = + body + +const x2 = m diff --git a/tests/errmsgs/t10542.nim b/tests/errmsgs/t10542.nim new file mode 100644 index 000000000..b57dbf18b --- /dev/null +++ b/tests/errmsgs/t10542.nim @@ -0,0 +1,24 @@ +discard """ + matrix: "--hintaserror:ConvFromXtoItselfNotNeeded" +""" + +# bug #10542 + +proc f(args: varargs[string, string], length: int) = + doAssert args.len == length + +# main use case that requires type conversion (no warning here) +f("a", "b", 2) +f("a", 1) + + +proc m(args: varargs[cstring, cstring]) = + doAssert args.len == 2 + +# main use case that requires type conversion (no warning here) +m("a", "b") + +# if an argument already is cstring there's a warning +let x: cstring = "x" +m("a", x) +m(x, "a") \ No newline at end of file diff --git a/tests/errmsgs/t10594.nim b/tests/errmsgs/t10594.nim new file mode 100644 index 000000000..d27dd6433 --- /dev/null +++ b/tests/errmsgs/t10594.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "expression has no address" + line: 7 +""" + +template foo(v: varargs[int]) = addr v +foo(1, 2) diff --git a/tests/errmsgs/t10734.nim b/tests/errmsgs/t10734.nim new file mode 100644 index 000000000..4e73db7cd --- /dev/null +++ b/tests/errmsgs/t10734.nim @@ -0,0 +1,20 @@ +discard """ + cmd: "nim check $file" + errormsg: "" + nimout: ''' +t10734.nim(19, 1) Error: invalid indentation +t10734.nim(19, 6) Error: invalid indentation +t10734.nim(20, 7) Error: expression expected, but found '[EOF]' +t10734.nim(18, 5) Error: 'proc' is not a concrete type; for a callback without parameters use 'proc()' +t10734.nim(19, 6) Error: undeclared identifier: 'p' +t10734.nim(19, 6) Error: expression 'p' has no type (or is ambiguous) +t10734.nim(19, 6) Error: 'p' cannot be assigned to +t10734.nim(17, 3) Hint: 'T' is declared but not used [XDeclaredButNotUsed] +''' +""" + +type + T = object + a: +proc p = + case \ No newline at end of file diff --git a/tests/errmsgs/t10735.nim b/tests/errmsgs/t10735.nim new file mode 100644 index 000000000..a39cd196e --- /dev/null +++ b/tests/errmsgs/t10735.nim @@ -0,0 +1,68 @@ +discard """ + cmd: "nim check $file" + errormsg: "illformed AST: case buf[pos]" + nimout: ''' +t10735.nim(65, 5) Error: 'let' symbol requires an initialization +t10735.nim(66, 10) Error: undeclared identifier: 'pos' +t10735.nim(66, 10) Error: expression 'pos' has no type (or is ambiguous) +t10735.nim(66, 10) Error: expression 'pos' has no type (or is ambiguous) +t10735.nim(66, 9) Error: type mismatch: got <cstring, > +but expected one of: +proc `[]`(s: string; i: BackwardsIndex): char + first type mismatch at position: 1 + required type for s: string + but expression 'buf' is of type: cstring +proc `[]`(s: var string; i: BackwardsIndex): var char + first type mismatch at position: 1 + required type for s: var string + but expression 'buf' is of type: cstring +proc `[]`[I: Ordinal; T](a: T; i: I): T + first type mismatch at position: 0 +proc `[]`[Idx, T; U, V: Ordinal](a: array[Idx, T]; x: HSlice[U, V]): seq[T] + first type mismatch at position: 1 + required type for a: array[Idx, T] + but expression 'buf' is of type: cstring +proc `[]`[Idx, T](a: array[Idx, T]; i: BackwardsIndex): T + first type mismatch at position: 1 + required type for a: array[Idx, T] + but expression 'buf' is of type: cstring +proc `[]`[Idx, T](a: var array[Idx, T]; i: BackwardsIndex): var T + first type mismatch at position: 1 + required type for a: var array[Idx, T] + but expression 'buf' is of type: cstring +proc `[]`[T, U: Ordinal](s: string; x: HSlice[T, U]): string + first type mismatch at position: 1 + required type for s: string + but expression 'buf' is of type: cstring +proc `[]`[T; U, V: Ordinal](s: openArray[T]; x: HSlice[U, V]): seq[T] + first type mismatch at position: 1 + required type for s: openArray[T] + but expression 'buf' is of type: cstring +proc `[]`[T](s: openArray[T]; i: BackwardsIndex): T + first type mismatch at position: 1 + required type for s: openArray[T] + but expression 'buf' is of type: cstring +proc `[]`[T](s: var openArray[T]; i: BackwardsIndex): var T + first type mismatch at position: 1 + required type for s: var openArray[T] + but expression 'buf' is of type: cstring +template `[]`(a: WideCStringObj; idx: int): Utf16Char + first type mismatch at position: 1 + required type for a: WideCStringObj + but expression 'buf' is of type: cstring +template `[]`(s: string; i: int): char + first type mismatch at position: 1 + required type for s: string + but expression 'buf' is of type: cstring + +expression: buf[pos] +t10735.nim(66, 9) Error: expression '' has no type (or is ambiguous) +t10735.nim(68, 3) Error: illformed AST: case buf[pos] +''' + joinable: false +""" + +let buf: cstring +case buf[pos] +else: + case buf[pos] diff --git a/tests/errmsgs/t1154.nim b/tests/errmsgs/t1154.nim index 7fcbf8a27..fee9d0ad6 100644 --- a/tests/errmsgs/t1154.nim +++ b/tests/errmsgs/t1154.nim @@ -1,11 +1,11 @@ discard """ -errormsg: "invalid type: 'expr' in this context: 'proc (a: varargs[expr])' for proc" +errormsg: "invalid type: 'untyped' in this context: 'proc (a: varargs[untyped])' for proc" line: 8 """ import typetraits -proc foo(a:varargs[expr]) = +proc foo(a:varargs[untyped]) = echo a[0].type.name foo(1) diff --git a/tests/errmsgs/t12844.nim b/tests/errmsgs/t12844.nim new file mode 100644 index 000000000..a274b72b4 --- /dev/null +++ b/tests/errmsgs/t12844.nim @@ -0,0 +1,13 @@ +discard """ +cmd: "nim check $file" +errormsg: "invalid type: 'template (args: varargs[string])' for var. Did you mean to call the template with '()'?" +nimout: ''' +t12844.nim(11, 7) Error: invalid type: 'template (args: varargs[string])' for const. Did you mean to call the template with '()'? +t12844.nim(12, 5) Error: invalid type: 'template (args: varargs[string])' for var. Did you mean to call the template with '()'?''' +""" + +template z*(args: varargs[string, `$`]) = + discard +const x = z +var y = z + diff --git a/tests/errmsgs/t14444.nim b/tests/errmsgs/t14444.nim new file mode 100644 index 000000000..27365236e --- /dev/null +++ b/tests/errmsgs/t14444.nim @@ -0,0 +1,14 @@ +discard """ + matrix: "--hints:off" + exitcode: "1" + output: ''' +t14444.nim(13) t14444 +fatal.nim(53) sysFatal +Error: unhandled exception: index out of bounds, the container is empty [IndexDefect] +''' +""" + +when true: # bug #14444 + var i: string + i[10] = 'j' + echo i \ No newline at end of file diff --git a/tests/errmsgs/t16654.nim b/tests/errmsgs/t16654.nim new file mode 100644 index 000000000..b2b57619b --- /dev/null +++ b/tests/errmsgs/t16654.nim @@ -0,0 +1,12 @@ +discard """ + cmd: "nim check $options $file" + errormsg: "type mismatch: got <int literal(1), proc (r: GenericParam): auto>" +""" + +when true: # bug #16654 + func fn[T](a: T, op: proc(a: T): float) = discard + proc main() = + let v = 1 + proc bar(r: auto): auto = v + fn(1, bar) + main() diff --git a/tests/errmsgs/t17460.nim b/tests/errmsgs/t17460.nim new file mode 100644 index 000000000..bb8e21198 --- /dev/null +++ b/tests/errmsgs/t17460.nim @@ -0,0 +1,19 @@ +discard """ + cmd: "nim check $options $file" + errormsg: "tuple expected for tuple unpacking, but got 'array[0..2, int]'" +""" + +iterator xclusters*[T](a: openArray[T]; s: static[int]): array[s, T] {.inline.} = + var result: array[s, T] # iterators have no default result variable + var i = 0 + while i < len(a): + for j, x in mpairs(result): + x = a[(i + j) mod len(a)] + yield result + inc(i) + +proc m = + for (i, j, k) in xclusters([1, 2, 3, 4, 5], 3): + echo i, j, k + +m() diff --git a/tests/errmsgs/t18327.nim b/tests/errmsgs/t18327.nim new file mode 100644 index 000000000..686a1bd0c --- /dev/null +++ b/tests/errmsgs/t18327.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "parameter 'n' requires a type" +""" + +proc fn3(n) = discard \ No newline at end of file diff --git a/tests/errmsgs/t18886.nim b/tests/errmsgs/t18886.nim new file mode 100644 index 000000000..8ed160c64 --- /dev/null +++ b/tests/errmsgs/t18886.nim @@ -0,0 +1,18 @@ +discard """ + cmd: "nim check --hints:off $file" + errormsg: "" + nimout: ''' +t18886.nim(18, 24) Error: ambiguous identifier: 'bar' -- you need a helper proc to disambiguate the following: + t18886.bar: proc (i: ptr int){.noSideEffect, gcsafe.} + t18886.bar: proc (i: ptr char){.noSideEffect, gcsafe.} +''' +""" + +type Foo = (proc(_: pointer): void) + + +proc bar(i: ptr[int]) = discard +proc bar(i: ptr[char]) = discard + + +let fooBar = cast[Foo](bar) \ No newline at end of file diff --git a/tests/errmsgs/t18983.nim b/tests/errmsgs/t18983.nim new file mode 100644 index 000000000..3451875cb --- /dev/null +++ b/tests/errmsgs/t18983.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "illegal recursion in type 'A'" +""" + +type + A* = A + B = (A,) diff --git a/tests/errmsgs/t19224.nim b/tests/errmsgs/t19224.nim new file mode 100644 index 000000000..7a9ecb2e7 --- /dev/null +++ b/tests/errmsgs/t19224.nim @@ -0,0 +1,12 @@ +discard """ +cmd: "nim check --hints:off $file" +errormsg: "" +nimout: ''' +t19224.nim(10, 10) Error: cannot infer element type of items([]) +t19224.nim(12, 10) Error: cannot infer element type of items(@[]) +''' +""" + +for _ in []: discard + +for _ in @[]: discard diff --git a/tests/errmsgs/t19882.nim b/tests/errmsgs/t19882.nim new file mode 100644 index 000000000..1f2f95ab7 --- /dev/null +++ b/tests/errmsgs/t19882.nim @@ -0,0 +1,10 @@ + +discard """ + errormsg: "cannot instantiate 'A[T, P]' inside of type definition: 'init'; Maybe generic arguments are missing?" +""" +type A[T,P] = object + b:T + c:P +proc init(): ref A = + new(result) +var a = init() diff --git a/tests/errmsgs/t19882_2.nim b/tests/errmsgs/t19882_2.nim new file mode 100644 index 000000000..7f3055a5d --- /dev/null +++ b/tests/errmsgs/t19882_2.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "cannot instantiate: 'A[T]'; the object's generic parameters cannot be inferred and must be explicitly given" +""" +type A[T] = object +var a = A() \ No newline at end of file diff --git a/tests/errmsgs/t21257.nim b/tests/errmsgs/t21257.nim new file mode 100644 index 000000000..eecdb1dfe --- /dev/null +++ b/tests/errmsgs/t21257.nim @@ -0,0 +1,20 @@ +discard """ + action: compile + cmd: "nim check $file" +""" + +type AC_WINCTRL_Fields* = distinct uint8 + +type AC_STATUSA_WSTATE0* {.pure.} = enum + ABOVE = 0x0, + INSIDE = 0x1, + BELOW = 0x2, + +type AC_WINCTRL_WINTSEL0* {.pure.} = enum + ABOVE = 0x0, + INSIDE = 0x1, + BELOW = 0x2, + OUTSIDE = 0x3, + +proc write*(WINTSEL0: AC_WINCTRL_WINTSEL0 = ABOVE) = + discard diff --git a/tests/errmsgs/t22097.nim b/tests/errmsgs/t22097.nim new file mode 100644 index 000000000..bb24ee8d3 --- /dev/null +++ b/tests/errmsgs/t22097.nim @@ -0,0 +1,9 @@ +discard """ + errormsg: "type mismatch: got <uint8>" +""" + +proc toUInt16(x: var uint16) = + discard + +var x = uint8(1) +toUInt16 x diff --git a/tests/errmsgs/t22284.nim b/tests/errmsgs/t22284.nim new file mode 100644 index 000000000..827155e6b --- /dev/null +++ b/tests/errmsgs/t22284.nim @@ -0,0 +1,25 @@ +discard """ + errormsg: "j(uRef, proc (config: F; sources: auto) {.raises: [].} = discard ) can raise an unlisted exception: Exception" +""" + +import std/macros + +macro h(): untyped = + result = newTree(nnkStmtList) + result.add quote do: + new int + +type F = object + +proc j[SecondarySources]( + uRef: ref SecondarySources, + u: proc (config: F, sources: ref SecondarySources)): F = + u(result, uRef) + +template programMain(body: untyped) = + proc main {.raises: [].} = body # doesn't SIGSEGV without this {.raises: [].} + main() + +programMain: + var uRef = h() + discard j(uRef, u = proc(config: F, sources: auto) {.raises: [].} = discard) \ No newline at end of file diff --git a/tests/errmsgs/t22753.nim b/tests/errmsgs/t22753.nim new file mode 100644 index 000000000..8a504109a --- /dev/null +++ b/tests/errmsgs/t22753.nim @@ -0,0 +1,52 @@ +discard """ +cmd: "nim check --hints:off $file" +errormsg: "type mismatch" +nimoutFull: true +nimout: ''' +t22753.nim(51, 13) Error: array expects two type parameters +t22753.nim(52, 1) Error: expression 'x' has no type (or is ambiguous) +t22753.nim(52, 1) Error: expression 'x' has no type (or is ambiguous) +t22753.nim(52, 2) Error: type mismatch: got <> +but expected one of: +proc `[]=`(s: var string; i: BackwardsIndex; x: char) + first type mismatch at position: 2 + required type for i: BackwardsIndex + but expression '0' is of type: int literal(0) +proc `[]=`[I: Ordinal; T, S](a: T; i: I; x: sink S) + first type mismatch at position: 0 +proc `[]=`[Idx, T; U, V: Ordinal](a: var array[Idx, T]; x: HSlice[U, V]; + b: openArray[T]) + first type mismatch at position: 2 + required type for x: HSlice[[]=.U, []=.V] + but expression '0' is of type: int literal(0) +proc `[]=`[Idx, T](a: var array[Idx, T]; i: BackwardsIndex; x: T) + first type mismatch at position: 2 + required type for i: BackwardsIndex + but expression '0' is of type: int literal(0) +proc `[]=`[T, U: Ordinal](s: var string; x: HSlice[T, U]; b: string) + first type mismatch at position: 2 + required type for x: HSlice[[]=.T, []=.U] + but expression '0' is of type: int literal(0) +proc `[]=`[T; U, V: Ordinal](s: var seq[T]; x: HSlice[U, V]; b: openArray[T]) + first type mismatch at position: 2 + required type for x: HSlice[[]=.U, []=.V] + but expression '0' is of type: int literal(0) +proc `[]=`[T](s: var openArray[T]; i: BackwardsIndex; x: T) + first type mismatch at position: 2 + required type for i: BackwardsIndex + but expression '0' is of type: int literal(0) +template `[]=`(a: WideCStringObj; idx: int; val: Utf16Char) + first type mismatch at position: 3 + required type for val: Utf16Char + but expression '9' is of type: int literal(9) +template `[]=`(s: string; i: int; val: char) + first type mismatch at position: 3 + required type for val: char + but expression '9' is of type: int literal(9) + +expression: x[0] = 9 +''' +""" + +var x: array[3] # bug #22753 +x[0] = 9 diff --git a/tests/errmsgs/t22852.nim b/tests/errmsgs/t22852.nim new file mode 100644 index 000000000..7c352a49c --- /dev/null +++ b/tests/errmsgs/t22852.nim @@ -0,0 +1,9 @@ +discard """ + exitcode: 1 + outputsub: ''' +Error: unhandled exception: value out of range: -2 notin 0 .. 9223372036854775807 [RangeDefect] +''' +""" + +# bug #22852 +echo [0][2..^2] diff --git a/tests/errmsgs/t22996.nim b/tests/errmsgs/t22996.nim new file mode 100644 index 000000000..3a51fd8b0 --- /dev/null +++ b/tests/errmsgs/t22996.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "invalid type: 'typedesc[string]' for const" +""" + +# bug #22996 +type MyObject = ref object + _ = string diff --git a/tests/errmsgs/t23060.nim b/tests/errmsgs/t23060.nim new file mode 100644 index 000000000..abb79bcc3 --- /dev/null +++ b/tests/errmsgs/t23060.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "undeclared identifier: '♔♕♖♗♘♙'" +""" + +♔♕♖♗♘♙ = 1 \ No newline at end of file diff --git a/tests/errmsgs/t23419.nim b/tests/errmsgs/t23419.nim new file mode 100644 index 000000000..59a72f081 --- /dev/null +++ b/tests/errmsgs/t23419.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "invalid type: 'void' in this context: '(array[0..-1, void],)' for var" +""" + +var a: (array[0, void], ) diff --git a/tests/errmsgs/t23435.nim b/tests/errmsgs/t23435.nim new file mode 100644 index 000000000..5e2e4c82a --- /dev/null +++ b/tests/errmsgs/t23435.nim @@ -0,0 +1,12 @@ +discard """ + outputsub: "Error: unhandled exception: value out of range: -15 notin 0 .. 9223372036854775807 [RangeDefect]" + exitcode: "1" +""" + +# bug #23435 +proc foo() = + for _ in @[1, 3, 5]: + discard "abcde"[25..<10] + break + +foo() diff --git a/tests/errmsgs/t23536.nim b/tests/errmsgs/t23536.nim new file mode 100644 index 000000000..610a85bab --- /dev/null +++ b/tests/errmsgs/t23536.nim @@ -0,0 +1,26 @@ +discard """ + matrix: "--stackTrace:on --excessiveStackTrace:off" +""" + +const expected = """ +wrong trace: +t23536.nim(22) t23536 +t23536.nim(17) foo +assertions.nim(41) failedAssertImpl +assertions.nim(36) raiseAssert +fatal.nim(53) sysFatal +""" + + +try: + proc foo = # bug #23536 + doAssert false + + for i in 0 .. 1: + + + foo() +except AssertionDefect: + let e = getCurrentException() + let trace = e.getStackTrace + doAssert "wrong trace:\n" & trace == expected diff --git a/tests/errmsgs/t2614.nim b/tests/errmsgs/t2614.nim new file mode 100644 index 000000000..031ecb9d1 --- /dev/null +++ b/tests/errmsgs/t2614.nim @@ -0,0 +1,21 @@ +discard """ + cmd: "nim check $options --hints:off $file" + errormsg: "" + nimout: ''' +t2614.nim(19, 27) Error: type mismatch: got <array[0..1, proc ()]> but expected 'array[0..1, proc (){.closure.}]' + Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'. +t2614.nim(21, 22) Error: type mismatch: got <seq[proc ()]> but expected 'seq[proc (){.closure.}]' + Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'. +''' +""" + +proc g +proc f = + if false: g() +proc g = + if false: f() + +var a = [f, g] # This works +var b: array[2, proc()] = [f, g] # Error + +var c: seq[proc()] = @[f, g] \ No newline at end of file diff --git a/tests/errmsgs/t5167_4.nim b/tests/errmsgs/t5167_4.nim index 7a263622b..dafd7754d 100644 --- a/tests/errmsgs/t5167_4.nim +++ b/tests/errmsgs/t5167_4.nim @@ -1,5 +1,5 @@ discard """ -errormsg: "type mismatch: got <proc [*missing parameters*](x: int) | proc (x: string){.gcsafe, locks: 0.}>" +errormsg: "type mismatch: got <proc [*missing parameters*](x: int) | proc (x: string){.gcsafe.}>" line: 19 """ diff --git a/tests/errmsgs/t5167_5.nim b/tests/errmsgs/t5167_5.nim index ab02f29f6..dea7e40b3 100644 --- a/tests/errmsgs/t5167_5.nim +++ b/tests/errmsgs/t5167_5.nim @@ -1,25 +1,25 @@ discard """ -cmd: "nim check $file" -errormsg: "'m' has unspecified generic parameters" -nimout: ''' -t5167_5.nim(20, 9) Error: 't' has unspecified generic parameters -t5167_5.nim(21, 5) Error: 't' has unspecified generic parameters -t5167_5.nim(23, 9) Error: 'm' has unspecified generic parameters -t5167_5.nim(24, 5) Error: 'm' has unspecified generic parameters -''' +cmd: "nim check --mm:refc $file" """ +# issue #11942 +discard newSeq[system]() #[tt.Error + ^ expression 'system' has no type (or is ambiguous)]# +# issue #5167 template t[B]() = echo "foo1" -macro m[T]: stmt = nil +macro m[T]: untyped = nil proc bar(x: proc (x: int)) = echo "bar" -let x = t -bar t - -let y = m -bar m +let x = t #[tt.Error + ^ 't' has unspecified generic parameters]# +bar t #[tt.Error +^ type mismatch: got <template [*missing parameters*]()>]# +let y = m #[tt.Error + ^ 'm' has unspecified generic parameters]# +bar m #[tt.Error +^ type mismatch: got <macro [*missing parameters*](): untyped{.noSideEffect, gcsafe.}>]# diff --git a/tests/errmsgs/t5282.nim b/tests/errmsgs/t5282.nim new file mode 100644 index 000000000..4da49d155 --- /dev/null +++ b/tests/errmsgs/t5282.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "illegal recursion in type 'x'" +""" + +type x = distinct x diff --git a/tests/errmsgs/t5870.nim b/tests/errmsgs/t5870.nim new file mode 100644 index 000000000..96966bcd7 --- /dev/null +++ b/tests/errmsgs/t5870.nim @@ -0,0 +1,17 @@ +discard """ +errormsg: "invalid type: 'SomeRefObj' in this context: 'seq[SomeRefObj]' for const" +line: 14 +""" + +# bug #5870 +type SomeRefObj = ref object of RootObj + someIntMember: int + +proc createSomeRefObj(v: int): SomeRefObj= + result.new() + result.someIntMember = v + +const compileTimeSeqOfRefObjs = @[createSomeRefObj(100500), createSomeRefObj(2)] + +for i in 0..1: + echo compileTimeSeqOfRefObjs[i].someIntMember diff --git a/tests/errmsgs/t6281.nim b/tests/errmsgs/t6281.nim new file mode 100644 index 000000000..59fda5077 --- /dev/null +++ b/tests/errmsgs/t6281.nim @@ -0,0 +1,9 @@ +discard """ +errormsg: "invalid type: 'SomeNumber' in this context: 'seq[SomeNumber]' for var" +line: 6 +""" + +var seqwat: seq[SomeNumber] = @[] + +proc foo(x: SomeNumber) = + seqwat.add(x) \ No newline at end of file diff --git a/tests/errmsgs/t6483.nim b/tests/errmsgs/t6483.nim new file mode 100644 index 000000000..0e977b36d --- /dev/null +++ b/tests/errmsgs/t6483.nim @@ -0,0 +1,31 @@ +discard """ + errormsg: "request to generate code for .compileTime proc: newSeq" + line: 21 +""" + +type + VarItem = object + onode: NimNode + nnode: NimNode + suffix: string + + VarState = object + scopes: seq[VarScope] + + VarScope = object + variables: seq[VarItem] + children: seq[VarScope] + +when true: + var scope1 = VarScope( + variables: newSeq[VarItem](), + children: newSeq[VarScope]() + ) + var scope2 = VarScope( + variables: newSeq[VarItem](), + children: newSeq[VarScope]() + ) + var state = VarState(scopes: newSeq[VarScope]()) + state.scopes.add(scope1) + state.scopes[0].children.add(scope2) + echo($state.scopes) \ No newline at end of file diff --git a/tests/errmsgs/t6499.nim b/tests/errmsgs/t6499.nim new file mode 100644 index 000000000..25e78fdbb --- /dev/null +++ b/tests/errmsgs/t6499.nim @@ -0,0 +1,6 @@ +discard """ + errormsg: "'chr' is a built-in and cannot be used as a first-class procedure" +""" + +# bug #6499 +let x = (chr, 0) diff --git a/tests/errmsgs/t6608.nim b/tests/errmsgs/t6608.nim new file mode 100644 index 000000000..88cbf42fd --- /dev/null +++ b/tests/errmsgs/t6608.nim @@ -0,0 +1,15 @@ +discard """ + cmd: "nim c --hints:off $file" + errormsg: "type mismatch: got <>" + nimout: '''t6608.nim(13, 4) Error: type mismatch: got <> +but expected one of: +AcceptCB = proc (s: string){.closure.}''' +""" + +type + AcceptCB = proc (s: string) + +proc x(x: AcceptCB) = + x() + +x() diff --git a/tests/errmsgs/t8064.nim b/tests/errmsgs/t8064.nim new file mode 100644 index 000000000..c35a3abcc --- /dev/null +++ b/tests/errmsgs/t8064.nim @@ -0,0 +1,9 @@ +import tables + +values + + +discard """ + # either this or "expression has no type": + errormsg: "ambiguous identifier: 'values' -- use one of the following:" +""" diff --git a/tests/errmsgs/t8339.nim b/tests/errmsgs/t8339.nim new file mode 100644 index 000000000..720e080c0 --- /dev/null +++ b/tests/errmsgs/t8339.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "type mismatch: got <seq[int]> but expected 'seq[float]'" + line: 8 +""" + +import sequtils + +var x: seq[float] = @[1].mapIt(it) diff --git a/tests/errmsgs/t8434.nim b/tests/errmsgs/t8434.nim new file mode 100644 index 000000000..5d962ee5c --- /dev/null +++ b/tests/errmsgs/t8434.nim @@ -0,0 +1,15 @@ +discard """ + errormsg: "type mismatch: got <byte, int literal(0)>" + nimout: '''but expected one of: +proc fun0[T1: int | float | object | array | seq](a1: T1; a2: int) + first type mismatch at position: 1 + required type for a1: T1: int or float or object or array or seq + but expression 'byte(1)' is of type: byte + +expression: fun0(byte(1), 0) +''' +""" + +proc fun0[T1:int|float|object|array|seq](a1:T1, a2:int)=discard + +fun0(byte(1), 0) diff --git a/tests/errmsgs/t8610.nim b/tests/errmsgs/t8610.nim new file mode 100644 index 000000000..ec99beae5 --- /dev/null +++ b/tests/errmsgs/t8610.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "invalid type: 'typedesc[int]' for const" +""" +## bug #8610 +const Foo = int diff --git a/tests/errmsgs/t8794.nim b/tests/errmsgs/t8794.nim new file mode 100644 index 000000000..36f05dbad --- /dev/null +++ b/tests/errmsgs/t8794.nim @@ -0,0 +1,23 @@ +discard """ + cmd: "nim check $options $file" +""" + +## issue #8794 + +import m8794 + +type Foo = object + a1: int + +discard Foo().a2 #[tt.Error + ^ undeclared field: 'a2' for type t8794.Foo [type declared in t8794.nim(9, 6)]]# + +type Foo3b = Foo3 +var x2: Foo3b + +proc getFun[T](): T = + var a: T + a + +discard getFun[type(x2)]().a3 #[tt.Error + ^ undeclared field: 'a3' for type m8794.Foo3 [type declared in m8794.nim(1, 6)]]# diff --git a/tests/errmsgs/t9768.nim b/tests/errmsgs/t9768.nim new file mode 100644 index 000000000..b5ff58367 --- /dev/null +++ b/tests/errmsgs/t9768.nim @@ -0,0 +1,31 @@ +discard """ + errormsg: "unhandled exception: t9768.nim(24, 3) `a < 4` [AssertionDefect]" + file: "std/assertions.nim" + matrix: "-d:nimPreviewSlimSystem" + nimout: ''' +stack trace: (most recent call last) +t9768.nim(29, 33) main +t9768.nim(24, 11) foo1 +''' +""" +import std/assertions + + + + + + + + + +## line 20 + +proc foo1(a: int): auto = + doAssert a < 4 + result = a * 2 + +proc main()= + static: + if foo1(1) > 0: discard foo1(foo1(2)) + +main() diff --git a/tests/errmsgs/t9908_01.nim b/tests/errmsgs/t9908_01.nim new file mode 100644 index 000000000..99bc8237d --- /dev/null +++ b/tests/errmsgs/t9908_01.nim @@ -0,0 +1,10 @@ +discard """ +errormsg: "ordinal type expected; given: string" +line: 10 +""" + +# https://github.com/nim-lang/Nim/issues/9908 + +type + X = enum + a = ("a", "b") diff --git a/tests/errmsgs/t9908_02.nim b/tests/errmsgs/t9908_02.nim new file mode 100644 index 000000000..4fc60b3df --- /dev/null +++ b/tests/errmsgs/t9908_02.nim @@ -0,0 +1,10 @@ +discard """ +errormsg: "ordinal type expected; given: float" +line: 10 +""" + +# https://github.com/nim-lang/Nim/pull/9909#issuecomment-445519287 + +type + E = enum + myVal = 80.9 diff --git a/tests/errmsgs/ta.nim b/tests/errmsgs/ta.nim new file mode 100644 index 000000000..31baae773 --- /dev/null +++ b/tests/errmsgs/ta.nim @@ -0,0 +1,12 @@ +discard """ + errormsg: "type mismatch: got <mc.typ>" + line: 12 +""" + +import mb, mc + +proc test(testing: mb.typ) = + discard + +var s: mc.typ +test(s) diff --git a/tests/errmsgs/tambparam.nim b/tests/errmsgs/tambparam.nim new file mode 100644 index 000000000..5b56a3fce --- /dev/null +++ b/tests/errmsgs/tambparam.nim @@ -0,0 +1,16 @@ +discard """ + matrix: "-d:testsConciseTypeMismatch" +""" + +import mambparam2, mambparam3 + +echo test #[tt.Error +^ type mismatch +Expression: echo test + [1] test: string | string + +Expected one of (first mismatch at [position]): +[1] proc echo(x: varargs[typed, `$$`]) + ambiguous identifier: 'test' -- use one of the following: + mambparam1.test: string + mambparam3.test: string]# diff --git a/tests/errmsgs/tambparam_legacy.nim b/tests/errmsgs/tambparam_legacy.nim new file mode 100644 index 000000000..bd99a3aac --- /dev/null +++ b/tests/errmsgs/tambparam_legacy.nim @@ -0,0 +1,14 @@ +import mambparam2, mambparam3 + +echo test #[tt.Error +^ type mismatch: got <string | string> +but expected one of: +proc echo(x: varargs[typed, `$$`]) + first type mismatch at position: 1 + required type for x: varargs[typed] + but expression 'test' is of type: None + ambiguous identifier: 'test' -- use one of the following: + mambparam1.test: string + mambparam3.test: string + +expression: echo test]# diff --git a/tests/errmsgs/tassignunpack.nim b/tests/errmsgs/tassignunpack.nim new file mode 100644 index 000000000..09d928a54 --- /dev/null +++ b/tests/errmsgs/tassignunpack.nim @@ -0,0 +1,3 @@ +var a, b = 0 +(a, b) = 1 #[tt.Error + ^ tuple expected for tuple unpacking, but got 'int literal(1)']# diff --git a/tests/errmsgs/tcall_with_default_arg.nim b/tests/errmsgs/tcall_with_default_arg.nim new file mode 100644 index 000000000..44752f1ee --- /dev/null +++ b/tests/errmsgs/tcall_with_default_arg.nim @@ -0,0 +1,18 @@ +discard """ +outputsub: '''tcall_with_default_arg.nim(8) fail''' +exitcode: 1 +""" +# issue: #5604 + +proc fail() = + raise newException(ValueError, "dead") + +proc getDefault(): int = 123 + +proc bar*(arg1: int = getDefault()) = + fail() + +proc anotherFoo(input: string) = + bar() + +anotherFoo("123") diff --git a/tests/errmsgs/tcannot_capture_builtin.nim b/tests/errmsgs/tcannot_capture_builtin.nim index 3b8aae241..65afa627e 100644 --- a/tests/errmsgs/tcannot_capture_builtin.nim +++ b/tests/errmsgs/tcannot_capture_builtin.nim @@ -1,5 +1,5 @@ discard """ -errormsg: "'+' cannot be passed to a procvar" +errormsg: "'+' is a built-in and cannot be used as a first-class procedure" line: 8 """ diff --git a/tests/errmsgs/tcase_stmt.nim b/tests/errmsgs/tcase_stmt.nim new file mode 100644 index 000000000..cf63b9c17 --- /dev/null +++ b/tests/errmsgs/tcase_stmt.nim @@ -0,0 +1,29 @@ +discard """ + cmd: "nim check --hints:off $file" + errormsg: "" + nimout: ''' +tcase_stmt.nim(22, 7) Error: selector must be of an ordinal type, float or string +tcase_stmt.nim(28, 6) Error: selector must be of an ordinal type, float or string + + + + + + + +''' +""" + + + +# bug #19682 +type A = object + +case A() +else: + discard + +# bug #20283 + +case @[] +else: discard diff --git a/tests/errmsgs/tconceptconstraint.nim b/tests/errmsgs/tconceptconstraint.nim index 9ab1708c7..066ec5bdb 100644 --- a/tests/errmsgs/tconceptconstraint.nim +++ b/tests/errmsgs/tconceptconstraint.nim @@ -1,8 +1,7 @@ discard """ errormsg: "cannot instantiate B" - line: 20 nimout: ''' -got: <type string> +got: <typedesc[string]> but expected: <T: A> ''' """ diff --git a/tests/errmsgs/tconcisetypemismatch.nim b/tests/errmsgs/tconcisetypemismatch.nim new file mode 100644 index 000000000..3093cc24e --- /dev/null +++ b/tests/errmsgs/tconcisetypemismatch.nim @@ -0,0 +1,23 @@ +discard """ + cmd: "nim c --hints:off -d:testsConciseTypeMismatch $file" + errormsg: "type mismatch" + nimout: ''' +tconcisetypemismatch.nim(23, 47) Error: type mismatch +Expression: int(inNanoseconds(t2 - t1)) / 100.5 + [1] int(inNanoseconds(t2 - t1)): int + [2] 100.5: float64 + +Expected one of (first mismatch at [position]): +[1] proc `/`(x, y: float): float +[1] proc `/`(x, y: float32): float32 +[2] proc `/`(x, y: int): float +''' +""" + +import std/monotimes +from times import inNanoseconds + +let t1 = getMonotime() +let result = 1 + 2 +let t2 = getMonotime() +echo "Elapsed: ", (t2 - t1).inNanoseconds.int / 100.5 diff --git a/tests/errmsgs/tconstinfo.nim b/tests/errmsgs/tconstinfo.nim new file mode 100644 index 000000000..170972b9f --- /dev/null +++ b/tests/errmsgs/tconstinfo.nim @@ -0,0 +1,7 @@ +# https://forum.nim-lang.org/t/9762 + +const foo = "abc" +case 'a' +of foo: echo "should error" #[tt.Error + ^ type mismatch: got <string> but expected 'char']# +else: discard diff --git a/tests/errmsgs/tconsttypemismatch.nim b/tests/errmsgs/tconsttypemismatch.nim new file mode 100644 index 000000000..727bfbffb --- /dev/null +++ b/tests/errmsgs/tconsttypemismatch.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "type mismatch" + file: "tconsttypemismatch.nim" + line: 7 +""" +# bug #2252 +const foo: int = 1000 / 30 diff --git a/tests/errmsgs/tdeclaredlocs.nim b/tests/errmsgs/tdeclaredlocs.nim new file mode 100644 index 000000000..926ebf217 --- /dev/null +++ b/tests/errmsgs/tdeclaredlocs.nim @@ -0,0 +1,92 @@ +discard """ + action: reject + matrix: "--declaredLocs --hints:off" + nimoutFull: true + nimout: ''' +tdeclaredlocs.nim(92, 3) Error: type mismatch: got <seq[MyInt2]> +but expected one of: +proc fn(a: Bam) [proc declared in tdeclaredlocs.nim(86, 6)] + first type mismatch at position: 1 + required type for a: Bam [object declared in tdeclaredlocs.nim(78, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] +proc fn(a: Goo[MyInt2]) [proc declared in tdeclaredlocs.nim(89, 6)] + first type mismatch at position: 1 + required type for a: Goo[MyInt2{char}] [object declared in tdeclaredlocs.nim(79, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] +proc fn(a: Goo[cint]) [proc declared in tdeclaredlocs.nim(88, 6)] + first type mismatch at position: 1 + required type for a: Goo[cint{int32}] [object declared in tdeclaredlocs.nim(79, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] +proc fn(a: array[3, Bar]) [proc declared in tdeclaredlocs.nim(82, 6)] + first type mismatch at position: 1 + required type for a: array[0..2, Bar] [object declared in tdeclaredlocs.nim(74, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] +proc fn(a: seq[Bar]) [proc declared in tdeclaredlocs.nim(81, 6)] + first type mismatch at position: 1 + required type for a: seq[Bar] [object declared in tdeclaredlocs.nim(74, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] +proc fn(a: seq[MyInt1]) [proc declared in tdeclaredlocs.nim(80, 6)] + first type mismatch at position: 1 + required type for a: seq[MyInt1{int}] [int declared in tdeclaredlocs.nim(72, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] +proc fn(a: set[Baz]) [proc declared in tdeclaredlocs.nim(84, 6)] + first type mismatch at position: 1 + required type for a: set[Baz{enum}] [enum declared in tdeclaredlocs.nim(75, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] +proc fn(a: set[MyInt2]) [proc declared in tdeclaredlocs.nim(83, 6)] + first type mismatch at position: 1 + required type for a: set[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] +proc fn(a: var SetBaz) [proc declared in tdeclaredlocs.nim(85, 6)] + first type mismatch at position: 1 + required type for a: var SetBaz [enum declared in tdeclaredlocs.nim(75, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] +proc fn(a: var ref ptr Bam) [proc declared in tdeclaredlocs.nim(87, 6)] + first type mismatch at position: 1 + required type for a: var ref ptr Bam [object declared in tdeclaredlocs.nim(78, 3)] + but expression 'a' is of type: seq[MyInt2{char}] [char declared in tdeclaredlocs.nim(73, 3)] + +expression: fn(a) +''' +""" + +#[ +see also: tests/errmsgs/tsigmatch.nim +]# + + + + + + + + + + + + + + +# line 70 +type + MyInt1 = int + MyInt2 = char + Bar = object + Baz = enum k0, k1 + Baz2 = Baz + SetBaz = set[Baz2] + Bam = ref object + Goo[T] = object +proc fn(a: seq[MyInt1]) = discard +proc fn(a: seq[Bar]) = discard +proc fn(a: array[3, Bar]) = discard +proc fn(a: set[MyInt2]) = discard +proc fn(a: set[Baz]) = discard +proc fn(a: var SetBaz) = discard +proc fn(a: Bam) = discard +proc fn(a: var ref ptr Bam) = discard +proc fn(a: Goo[cint]) = discard +proc fn(a: Goo[MyInt2]) = discard + +var a: seq[MyInt2] +fn(a) diff --git a/tests/errmsgs/tdetailed_position.nim b/tests/errmsgs/tdetailed_position.nim index ce5b18bbd..ecece7972 100644 --- a/tests/errmsgs/tdetailed_position.nim +++ b/tests/errmsgs/tdetailed_position.nim @@ -6,7 +6,7 @@ nimout: ''' but expected one of: proc main(a, b, c: string) first type mismatch at position: 1 - required type: string + required type for a: string but expression '1' is of type: int literal(1) expression: main(1, 2, 3) diff --git a/tests/errmsgs/tdistinct_nil.nim b/tests/errmsgs/tdistinct_nil.nim new file mode 100644 index 000000000..a2b403293 --- /dev/null +++ b/tests/errmsgs/tdistinct_nil.nim @@ -0,0 +1,23 @@ +discard """ + cmd: "nim check $file" + action: reject + nimout: ''' +tdistinct_nil.nim(23, 4) Error: type mismatch: got <typeof(nil)> +but expected one of: +proc foo(x: DistinctPointer) + first type mismatch at position: 1 + required type for x: DistinctPointer + but expression 'nil' is of type: typeof(nil) + +expression: foo(nil) +''' +""" + +type + DistinctPointer = distinct pointer + +proc foo(x: DistinctPointer) = + discard + +foo(DistinctPointer(nil)) +foo(nil) diff --git a/tests/errmsgs/tdont_show_system.nim b/tests/errmsgs/tdont_show_system.nim index 830113218..164fdd801 100644 --- a/tests/errmsgs/tdont_show_system.nim +++ b/tests/errmsgs/tdont_show_system.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "expression 'true' is of type 'bool' and has to be discarded" + errormsg: "expression 'true' is of type 'bool' and has to be used (or discarded)" line: 13 file: "tdont_show_system.nim" """ diff --git a/tests/errmsgs/temptysetparam.nim b/tests/errmsgs/temptysetparam.nim new file mode 100644 index 000000000..20763feda --- /dev/null +++ b/tests/errmsgs/temptysetparam.nim @@ -0,0 +1,5 @@ +discard """ + errormsg: "cannot infer the type of parameter 'x'" + line: 5 +""" +proc a(x = {}) = discard diff --git a/tests/errmsgs/tgcsafety.nim b/tests/errmsgs/tgcsafety.nim index 4d192db90..66496d364 100644 --- a/tests/errmsgs/tgcsafety.nim +++ b/tests/errmsgs/tgcsafety.nim @@ -1,14 +1,16 @@ discard """ cmd: "nim check $file" -errormsg: "type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Future[system.void]{.locks: <unknown>.}>" +errormsg: "type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Future[system.void]>" nimout: ''' -type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Future[system.void]{.locks: <unknown>.}> +tgcsafety.nim(31, 18) Error: type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Future[system.void]> but expected one of: proc serve(server: AsyncHttpServer; port: Port; - callback: proc (request: Request): Future[void]; address = ""): Future[void] + callback: proc (request: Request): Future[void] {.closure, gcsafe.}; + address = ""; assumedDescriptorsPerRequest = -1; domain = AF_INET): owned( + Future[void]) first type mismatch at position: 3 - required type: proc (request: Request): Future[system.void]{.closure, gcsafe.} - but expression 'cb' is of type: proc (req: Request): Future[system.void]{.locks: <unknown>.} + required type for callback: proc (request: Request): Future[system.void]{.closure, gcsafe.} + but expression 'cb' is of type: proc (req: Request): Future[system.void] This expression is not GC-safe. Annotate the proc with {.gcsafe.} to get extended error information. expression: serve(server, Port(7898), cb) diff --git a/tests/errmsgs/tgeneral_excepts.nim b/tests/errmsgs/tgeneral_excepts.nim new file mode 100644 index 000000000..8f8be797f --- /dev/null +++ b/tests/errmsgs/tgeneral_excepts.nim @@ -0,0 +1,10 @@ +discard """ +errormsg: "Only one general except clause is allowed after more specific exceptions" +""" + +try: + discard +except: + discard +except: + discard diff --git a/tests/errmsgs/tgenericconstraint.nim b/tests/errmsgs/tgenericconstraint.nim index e3093fead..b51fb3488 100644 --- a/tests/errmsgs/tgenericconstraint.nim +++ b/tests/errmsgs/tgenericconstraint.nim @@ -1,8 +1,7 @@ discard """ errormsg: "cannot instantiate B" - line: 14 nimout: ''' -got: <type int> +got: <typedesc[int]> but expected: <T: string or float> ''' """ diff --git a/tests/errmsgs/tgenericmismatchsegfault.nim b/tests/errmsgs/tgenericmismatchsegfault.nim new file mode 100644 index 000000000..dbb783cb3 --- /dev/null +++ b/tests/errmsgs/tgenericmismatchsegfault.nim @@ -0,0 +1,13 @@ +discard """ + matrix: "-d:testsConciseTypeMismatch" +""" + +template v[T](c: SomeOrdinal): T = T(c) +discard v[int, char]('A') #[tt.Error + ^ type mismatch +Expression: v[int, char]('A') + [1] 'A': char + +Expected one of (first mismatch at [position]): +[2] template v[T](c: SomeOrdinal): T + generic parameter mismatch, expected SomeOrdinal but got 'char' of type: char]# diff --git a/tests/errmsgs/tgenericmismatchsegfault_legacy.nim b/tests/errmsgs/tgenericmismatchsegfault_legacy.nim new file mode 100644 index 000000000..1532611b9 --- /dev/null +++ b/tests/errmsgs/tgenericmismatchsegfault_legacy.nim @@ -0,0 +1,10 @@ +template v[T](c: SomeOrdinal): T = T(c) +discard v[int, char]('A') #[tt.Error + ^ type mismatch: got <char> +but expected one of: +template v[T](c: SomeOrdinal): T + first type mismatch at position: 2 in generic parameters + required type for SomeOrdinal: SomeOrdinal + but expression 'char' is of type: char + +expression: v[int, char]('A')]# diff --git a/tests/errmsgs/tinconsistentgensym.nim b/tests/errmsgs/tinconsistentgensym.nim new file mode 100644 index 000000000..8e4c85106 --- /dev/null +++ b/tests/errmsgs/tinconsistentgensym.nim @@ -0,0 +1,25 @@ +discard """ + cmd: "nim check --hints:off $file" +""" + +block: + template foo = + when false: + let x = 123 + else: + template x: untyped {.inject.} = 456 + echo x #[tt.Error + ^ undeclared identifier: 'x`gensym0'; if declared in a template, this identifier may be inconsistently marked inject or gensym]# + foo() + +block: + template foo(y: static bool) = + block: + when y: + let x {.gensym.} = 123 + else: + let x {.inject.} = 456 + echo x #[tt.Error + ^ undeclared identifier: 'x']# + foo(false) + foo(true) diff --git a/tests/errmsgs/tinteger_literals.nim b/tests/errmsgs/tinteger_literals.nim new file mode 100644 index 000000000..f90ab14a1 --- /dev/null +++ b/tests/errmsgs/tinteger_literals.nim @@ -0,0 +1,14 @@ +discard """ + cmd: "nim check $file" +""" +# high(uint64) + 1 +discard 18446744073709551616'u64 #[tt.Error + ^ number out of range: '18446744073709551616'u64' ]# +# high(int64) + 1 +discard 9223372036854775808'i64 #[tt.Error + ^ number out of range: '9223372036854775808'i64' ]# +# high(int64) + 1 +discard 9223372036854775808 #[tt.Error + ^ number out of range: '9223372036854775808' ]# +discard 300'u8 #[tt.Error + ^ number out of range: '300'u8' ]# diff --git a/tests/errmsgs/tinvalidinout.nim b/tests/errmsgs/tinvalidinout.nim index 1fa3805ee..268bcf4d5 100644 --- a/tests/errmsgs/tinvalidinout.nim +++ b/tests/errmsgs/tinvalidinout.nim @@ -9,7 +9,7 @@ tinvalidinout.nim(18, 9) Error: the 'in' modifier can be used only with imported """ type - Foo {.header: "foo.h", importcpp.} [in T] = object + Foo[in T] {.header: "foo.h", importcpp.} = object Bar[out X] = object x: int diff --git a/tests/errmsgs/tmacroerrorproc.nim b/tests/errmsgs/tmacroerrorproc.nim new file mode 100644 index 000000000..86726af72 --- /dev/null +++ b/tests/errmsgs/tmacroerrorproc.nim @@ -0,0 +1,13 @@ +discard """ + errormsg: "Expected a node of kind nnkCharLit, got nnkCommand" + file: "tmacroerrorproc.nim" + line: 13 +""" +# issue #4915 +import macros + +macro mixer(n: typed): untyped = + expectKind(n[0], nnkCharLit) + +mixer: + echo "owh" diff --git a/tests/errmsgs/tmake_tuple_visible.nim b/tests/errmsgs/tmake_tuple_visible.nim index e059368ad..90b965c64 100644 --- a/tests/errmsgs/tmake_tuple_visible.nim +++ b/tests/errmsgs/tmake_tuple_visible.nim @@ -1,9 +1,6 @@ discard """ - errormsg: '''got <tuple of (type NimEdAppWindow, int)>''' - line: 22 - nimout: '''got <tuple of (type NimEdAppWindow, int)> -but expected one of: -template xxx(tn: typedesc; i: int)''' + errormsg: '''Mixing types and values in tuples is not allowed.''' + line: 19 """ type diff --git a/tests/errmsgs/tmetaobjectfields.nim b/tests/errmsgs/tmetaobjectfields.nim new file mode 100644 index 000000000..47d3acf18 --- /dev/null +++ b/tests/errmsgs/tmetaobjectfields.nim @@ -0,0 +1,75 @@ +discard """ + cmd: "nim check --hints:off $file" + action: "reject" + nimout: ''' +tmetaobjectfields.nim(26, 5) Error: 'array' is not a concrete type +tmetaobjectfields.nim(30, 5) Error: 'seq' is not a concrete type +tmetaobjectfields.nim(34, 5) Error: 'set' is not a concrete type +tmetaobjectfields.nim(37, 3) Error: 'sink' is not a concrete type +tmetaobjectfields.nim(39, 3) Error: 'lent' is not a concrete type +tmetaobjectfields.nim(56, 16) Error: 'seq' is not a concrete type +tmetaobjectfields.nim(60, 5) Error: 'ptr' is not a concrete type +tmetaobjectfields.nim(61, 5) Error: 'ref' is not a concrete type +tmetaobjectfields.nim(62, 5) Error: 'auto' is not a concrete type +tmetaobjectfields.nim(63, 5) Error: 'UncheckedArray' is not a concrete type +tmetaobjectfields.nim(68, 5) Error: 'object' is not a concrete type +tmetaobjectfields.nim(72, 5) Error: 'Type3011:ObjectType' is not a concrete type +''' +""" + + +# bug #6982 +# bug #19546 +# bug #23531 +type + ExampleObj1 = object + arr: array + +type + ExampleObj2 = object + arr: seq + +type + ExampleObj3 = object + arr: set + +type A = object + b: sink + # a: openarray + c: lent + +type PropertyKind = enum + tInt, + tFloat, + tBool, + tString, + tArray + +type + Property = ref PropertyObj + PropertyObj = object + case kind: PropertyKind + of tInt: intValue: int + of tFloat: floatValue: float + of tBool: boolValue: bool + of tString: stringValue: string + of tArray: arrayValue: seq + +type + RegressionTest = object + a: ptr + b: ref + c: auto + d: UncheckedArray + +# bug #3011 +type + Type3011 = ref object + context: ref object + +type + Value3011 = ref object + typ: Type3011 + +proc x3011(): Value3011 = + nil diff --git a/tests/errmsgs/tmultiple_finally.nim b/tests/errmsgs/tmultiple_finally.nim new file mode 100644 index 000000000..519a80145 --- /dev/null +++ b/tests/errmsgs/tmultiple_finally.nim @@ -0,0 +1,12 @@ +discard """ +errormsg: "Only one finally is allowed after all other branches" +""" + +try: + discard +finally: + discard +finally: + discard + + diff --git a/tests/errmsgs/tnested_empty_seq.nim b/tests/errmsgs/tnested_empty_seq.nim index ffe8bc3ee..871b0ee85 100644 --- a/tests/errmsgs/tnested_empty_seq.nim +++ b/tests/errmsgs/tnested_empty_seq.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "invalid type: 'empty' in this context: 'array[0..0, tuple of (string, seq[empty])]' for var" + errormsg: "invalid type: 'empty' in this context: 'array[0..0, (string, seq[empty])]' for var" line: 8 """ diff --git a/tests/errmsgs/tnested_generic_instantiation.nim b/tests/errmsgs/tnested_generic_instantiation.nim new file mode 100644 index 000000000..ab9ab54cd --- /dev/null +++ b/tests/errmsgs/tnested_generic_instantiation.nim @@ -0,0 +1,24 @@ +discard """ +action: compile +""" + +# bug #4766 + +type + Plain = ref object + discard + + Wrapped[T] = object + value: T + +converter toWrapped[T](value: T): Wrapped[T] = + Wrapped[T](value: value) + +let result = Plain() +discard $result + +proc foo[T2](a: Wrapped[T2]) = + # Error: generic instantiation too nested + discard $a + +foo(result) diff --git a/tests/errmsgs/tnested_generic_instantiation2.nim b/tests/errmsgs/tnested_generic_instantiation2.nim new file mode 100644 index 000000000..c2ec31af8 --- /dev/null +++ b/tests/errmsgs/tnested_generic_instantiation2.nim @@ -0,0 +1,27 @@ +discard """ +action: compile +""" + +#[ +bug #4766 +see also: tnested_generic_instantiation.nim +]# + +proc toString*[T](x: T) = + for name, value in fieldPairs(x): + when compiles(toString(value)): + discard + toString(value) + +type + Plain = ref object + discard + + Wrapped[T] = object + value: T + +converter toWrapped[T](value: T): Wrapped[T] = + Wrapped[T](value: value) + +let result = Plain() +toString(result) diff --git a/tests/errmsgs/tnnodeadd.nim b/tests/errmsgs/tnnodeadd.nim new file mode 100644 index 000000000..61921883e --- /dev/null +++ b/tests/errmsgs/tnnodeadd.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "cannot add to node kind: nnkInt8Lit" + line: 7 +""" +import macros +macro t(x: untyped): untyped = + x.add(newEmptyNode()) +t(38'i8) diff --git a/tests/errmsgs/tnnodeindex.nim b/tests/errmsgs/tnnodeindex.nim new file mode 100644 index 000000000..5e37e7977 --- /dev/null +++ b/tests/errmsgs/tnnodeindex.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "index 5 not in 0 .. 2" + line: 7 +""" +import macros +macro t(x: untyped): untyped = + result = x[5] +t([1, 2, 3]) diff --git a/tests/errmsgs/tnnodeindexkind.nim b/tests/errmsgs/tnnodeindexkind.nim new file mode 100644 index 000000000..9ea045e66 --- /dev/null +++ b/tests/errmsgs/tnnodeindexkind.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "cannot set child of node kind: nnkStrLit" + line: 7 +""" +import macros +macro t(x: untyped): untyped = + x[0] = newEmptyNode() +t("abc") diff --git a/tests/errmsgs/tnon_concrete_cast.nim b/tests/errmsgs/tnon_concrete_cast.nim index e4ae890ce..9e05c736c 100644 --- a/tests/errmsgs/tnon_concrete_cast.nim +++ b/tests/errmsgs/tnon_concrete_cast.nim @@ -34,7 +34,7 @@ proc write(rw: var MyReadWrite; value: SomeNumber): void = proc write[T](rw: var MyReadWrite; value: seq[T]): void = rw.write value.len let dst = cast[ptr SomeNumber](cast[uint](rw.memfile.mem) + uint(rw.offset)) - let src = cast[pointer](value[0].unsafeAddr) + let src = cast[pointer](value[0].addr) let size = sizeof(T) * value.len copyMem(dst, src, size) rw.offset += size diff --git a/tests/errmsgs/tnoop.nim b/tests/errmsgs/tnoop.nim new file mode 100644 index 000000000..f55f2441a --- /dev/null +++ b/tests/errmsgs/tnoop.nim @@ -0,0 +1,12 @@ +discard """ + nimout: ''' + found 'a' [var declared in tnoop.nim(10, 3)] + ''' + file: "tnoop.nim" + errormsg: "attempting to call routine: 'a'" +""" + +var + a: int + +a() diff --git a/tests/errmsgs/tproc_mismatch.nim b/tests/errmsgs/tproc_mismatch.nim new file mode 100644 index 000000000..16f319f3b --- /dev/null +++ b/tests/errmsgs/tproc_mismatch.nim @@ -0,0 +1,74 @@ +discard """ + action: reject + cmd: '''nim check --hints:off $options $file''' + nimoutFull: true + nimout: ''' +tproc_mismatch.nim(38, 52) Error: type mismatch: got <proc (a: int, c: float){.cdecl, noSideEffect, gcsafe.}> but expected 'proc (a: int, c: float){.closure, noSideEffect.}' + Calling convention mismatch: got '{.cdecl.}', but expected '{.closure.}'. +tproc_mismatch.nim(42, 6) Error: type mismatch: got <proc (){.inline, noSideEffect, gcsafe.}> +but expected one of: +proc bar(a: proc ()) + first type mismatch at position: 1 + required type for a: proc (){.closure.} + but expression 'fn1' is of type: proc (){.inline, noSideEffect, gcsafe.} + Calling convention mismatch: got '{.inline.}', but expected '{.closure.}'. + +expression: bar(fn1) +tproc_mismatch.nim(46, 8) Error: type mismatch: got <proc (){.inline, noSideEffect, gcsafe.}> but expected 'proc (){.closure.}' + Calling convention mismatch: got '{.inline.}', but expected '{.closure.}'. +tproc_mismatch.nim(51, 8) Error: type mismatch: got <proc ()> but expected 'proc (){.closure, noSideEffect.}' + Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'. + Pragma mismatch: got '{..}', but expected '{.noSideEffect.}'. +tproc_mismatch.nim(55, 8) Error: type mismatch: got <proc (a: int){.noSideEffect, gcsafe.}> but expected 'proc (a: float){.closure.}' + Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'. +tproc_mismatch.nim(64, 9) Error: type mismatch: got <proc (a: int)> but expected 'proc (a: int){.closure, gcsafe.}' + Calling convention mismatch: got '{.nimcall.}', but expected '{.closure.}'. + Pragma mismatch: got '{..}', but expected '{.gcsafe.}'. +tproc_mismatch.nim(72, 9) Error: type mismatch: got <proc (a: int): int{.nimcall.}> but expected 'proc (a: int): int{.cdecl.}' + Calling convention mismatch: got '{.nimcall.}', but expected '{.cdecl.}'. +tproc_mismatch.nim(73, 9) Error: type mismatch: got <proc (a: int): int{.cdecl.}> but expected 'proc (a: int): int{.nimcall.}' + Calling convention mismatch: got '{.cdecl.}', but expected '{.nimcall.}'. +''' +""" + + + +block: # CallConv mismatch + func a(a: int, c: float) {.cdecl.} = discard + var b: proc(a: int, c: float) {.noSideEffect.} = a +block: # Parameter CallConv mismatch + proc fn1() {.inline.} = discard + proc bar(a: proc()) = discard + bar(fn1) +block: # CallConv mismatch + proc fn1() {.inline.} = discard + var fn: proc() + fn = fn1 +block: # Pragma mismatch + var a = "" + proc fn1() = a.add "b" + var fn: proc() {.noSideEffect.} + fn = fn1 +block: # Fail match not do to Pragma or CallConv + proc fn1(a: int) = discard + var fn: proc(a: float) + fn = fn1 +block: # Infered noSideEffect assign + type Foo = ref object + x0: int + var g0 = Foo(x0: 1) + proc fn1(a: int) = g0.x0 = a + var fn2: proc(a: int) + var fn3: proc(a: int) {.gcsafe.} + fn2 = fn1 + fn3 = fn1 +block: # Indrection through pragmas + {.pragma: inl1, inline.} + {.pragma: inl2, inline.} + {.pragma: p1, nimcall.} + {.pragma: p2, cdecl.} + var fn1: proc(a: int): int {.inl1, p1.} + var fn2: proc(a: int): int {.inl2, p2.} + fn2 = fn1 + fn1 = fn2 + diff --git a/tests/errmsgs/tproper_stacktrace.nim b/tests/errmsgs/tproper_stacktrace.nim index 134946651..b0a008840 100644 --- a/tests/errmsgs/tproper_stacktrace.nim +++ b/tests/errmsgs/tproper_stacktrace.nim @@ -1,4 +1,5 @@ discard """ + matrix: "--stackTrace:on --hint:all:off --warnings:off" output: '''ok''' """ import strscans, strutils @@ -6,7 +7,7 @@ import strscans, strutils proc raiseTestException*() = raise newException(Exception, "test") -proc matchStackTrace(actualEntries: openarray[StackTraceEntry], expected: string) = +proc matchStackTrace(actualEntries: openArray[StackTraceEntry], expected: string) = var expectedEntries = newSeq[StackTraceEntry]() var i = 0 @@ -22,7 +23,7 @@ proc matchStackTrace(actualEntries: openarray[StackTraceEntry], expected: string var line: int if not scanf(l, "$s$w.nim($i) $w", filename, line, procname): doAssert(false, "Wrong expected stack trace") - checkEqual($actualEntries[i].filename, filename & ".nim", "file name") + checkEqual(actualEntries[i].filename.`$`.split('/')[^1], filename & ".nim", "file name") if line != 0: checkEqual(actualEntries[i].line, line, "line number") checkEqual($actualEntries[i].procname, procname, "proc name") @@ -66,7 +67,7 @@ template verifyStackTrace*(expectedStackTrace: string, body: untyped) = -when isMainModule: +when true: # <-- Align with line 70 in the text editor block: proc bar() = @@ -76,10 +77,10 @@ when isMainModule: bar() const expectedStackTrace = """ - tproper_stacktrace.nim(86) tproper_stacktrace - tproper_stacktrace.nim(76) foo - tproper_stacktrace.nim(73) bar - tproper_stacktrace.nim(7) raiseTestException + tproper_stacktrace.nim(87) tproper_stacktrace + tproper_stacktrace.nim(77) foo + tproper_stacktrace.nim(74) bar + tproper_stacktrace.nim(8) raiseTestException """ verifyStackTrace expectedStackTrace: @@ -93,9 +94,9 @@ when isMainModule: bar(x) const expectedStackTrace = """ - tproper_stacktrace.nim(103) tproper_stacktrace - tproper_stacktrace.nim(90) bar - tproper_stacktrace.nim(7) raiseTestException + tproper_stacktrace.nim(104) tproper_stacktrace + tproper_stacktrace.nim(91) bar + tproper_stacktrace.nim(8) raiseTestException """ verifyStackTrace expectedStackTrace: @@ -110,10 +111,10 @@ when isMainModule: bar() const expectedStackTrace = """ - tproper_stacktrace.nim(120) tproper_stacktrace - tproper_stacktrace.nim(110) foo - tproper_stacktrace.nim(107) bar - tproper_stacktrace.nim(7) raiseTestException + tproper_stacktrace.nim(121) tproper_stacktrace + tproper_stacktrace.nim(111) foo + tproper_stacktrace.nim(108) bar + tproper_stacktrace.nim(8) raiseTestException """ verifyStackTrace expectedStackTrace: @@ -129,10 +130,10 @@ when isMainModule: bar() const expectedStackTrace = """ - tproper_stacktrace.nim(139) tproper_stacktrace - tproper_stacktrace.nim(129) foo - tproper_stacktrace.nim(125) baz - tproper_stacktrace.nim(7) raiseTestException + tproper_stacktrace.nim(140) tproper_stacktrace + tproper_stacktrace.nim(130) foo + tproper_stacktrace.nim(126) baz + tproper_stacktrace.nim(8) raiseTestException """ verifyStackTrace expectedStackTrace: diff --git a/tests/errmsgs/tproper_stacktrace2.nim b/tests/errmsgs/tproper_stacktrace2.nim index 44b208c87..5a6ca3fcb 100644 --- a/tests/errmsgs/tproper_stacktrace2.nim +++ b/tests/errmsgs/tproper_stacktrace2.nim @@ -1,5 +1,6 @@ discard """ - outputsub: '''tproper_stacktrace2.nim(20) main''' + matrix: "--stackTrace:on" + outputsub: '''tproper_stacktrace2.nim(21) main''' exitcode: 1 """ diff --git a/tests/errmsgs/tproper_stacktrace3.nim b/tests/errmsgs/tproper_stacktrace3.nim index c292fa092..97d63e6ec 100644 --- a/tests/errmsgs/tproper_stacktrace3.nim +++ b/tests/errmsgs/tproper_stacktrace3.nim @@ -1,5 +1,6 @@ discard """ - outputsub: '''tproper_stacktrace3.nim(21) main''' + matrix: "--stackTrace:on" + outputsub: '''tproper_stacktrace3.nim(22) main''' exitcode: 1 """ diff --git a/tests/errmsgs/treportunused.nim b/tests/errmsgs/treportunused.nim new file mode 100644 index 000000000..46afe163d --- /dev/null +++ b/tests/errmsgs/treportunused.nim @@ -0,0 +1,65 @@ +discard """ + matrix: "--hint:all:off --hint:XDeclaredButNotUsed" + nimoutFull: true + nimout: ''' +treportunused.nim(51, 5) Hint: 'A' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(52, 5) Hint: 'B' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(55, 5) Hint: 'D' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(56, 5) Hint: 'E' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(59, 5) Hint: 'G' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(60, 5) Hint: 'H' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(64, 5) Hint: 'K' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(65, 5) Hint: 'L' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(31, 10) Hint: 's1' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(32, 10) Hint: 's2' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(33, 10) Hint: 's3' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(34, 6) Hint: 's4' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(35, 6) Hint: 's5' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(36, 7) Hint: 's6' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(37, 7) Hint: 's7' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(38, 5) Hint: 's8' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(39, 5) Hint: 's9' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(40, 6) Hint: 's10' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(41, 6) Hint: 's11' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(45, 3) Hint: 'v0.99' is declared but not used [XDeclaredButNotUsed] +treportunused.nim(46, 3) Hint: 'v0.99.99' is declared but not used [XDeclaredButNotUsed] +''' +action: compile +""" + +# bug #9764 +iterator s1(a:string): int = discard +iterator s2(): int = discard +template s3(): untyped = 123 +proc s4(): int = 123 +proc s5[T](a: T): int = 123 +macro s6(a: int): untyped = discard +const s7 = 0 +let s8 = 0 +var s9: int +type s10 = object +type s11 = type(1.2) + +# bug #14407 (requires `compiler/nim.cfg` containing define:nimPreviewFloatRoundtrip) +let + `v0.99` = "0.99" + `v0.99.99` = "0.99.99" + +block: # bug #18201 + # Test that unused type aliases raise hint XDeclaredButNotUsed. + type + A = int + B = distinct int + + C = object + D = C + E = distinct C + + F = string + G = F + H = distinct F + + J = enum + Foo + K = J + L = distinct J diff --git a/tests/errmsgs/tshow_asgn.nim b/tests/errmsgs/tshow_asgn.nim index 1627c9b71..28a9acbeb 100644 --- a/tests/errmsgs/tshow_asgn.nim +++ b/tests/errmsgs/tshow_asgn.nim @@ -1,7 +1,7 @@ discard """ errormsg: "type mismatch: got <int> but expected 'cshort = int16'" line: 12 - column: 10 + column: 27 file: "tshow_asgn.nim" """ diff --git a/tests/errmsgs/tsigmatch.nim b/tests/errmsgs/tsigmatch.nim new file mode 100644 index 000000000..85ed34169 --- /dev/null +++ b/tests/errmsgs/tsigmatch.nim @@ -0,0 +1,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") + diff --git a/tests/errmsgs/tsigmatch2.nim b/tests/errmsgs/tsigmatch2.nim new file mode 100644 index 000000000..31c966337 --- /dev/null +++ b/tests/errmsgs/tsigmatch2.nim @@ -0,0 +1,47 @@ +discard """ + cmd: "nim check --showAllMismatches:on --hints:off $file" + nimout: ''' +tsigmatch2.nim(40, 14) Error: type mismatch: got <float64> +but expected one of: +proc foo(args: varargs[string, myproc]): string + first type mismatch at position: 1 + required type for args: varargs[string] + but expression '1.2' is of type: float64 +proc foo(i: Foo): string + first type mismatch at position: 1 + required type for i: Foo + but expression '1.2' is of type: float64 + +expression: foo(1.2) +tsigmatch2.nim(40, 14) Error: expression '' has no type (or is ambiguous) +tsigmatch2.nim(46, 3) Error: type mismatch: got <int literal(1)> +but expected one of: +proc foo(args: varargs[string, myproc]) + first type mismatch at position: 1 + required type for args: varargs[string] + but expression '1' is of type: int literal(1) + +expression: foo 1 +''' + errormsg: "type mismatch" +""" + + +# line 30 +type Foo = object +block: # issue #13182 + proc myproc(a: int): string = $("myproc", a) + proc foo(args: varargs[string, myproc]): string = $args + + proc foo(i: Foo): string = "in foo(i)" + static: doAssert foo(Foo()) == "in foo(i)" + static: doAssert foo(1) == """["(\"myproc\", 1)"]""" + doAssert not compiles(foo(1.2)) + discard foo(1.2) + +block: + proc myproc[T](x: T): string = + let temp = 12.isNil + proc foo(args: varargs[string, myproc]) = discard + foo 1 +static: echo "done" diff --git a/tests/errmsgs/tsimpletypecheck.nim b/tests/errmsgs/tsimpletypecheck.nim new file mode 100644 index 000000000..422437d3a --- /dev/null +++ b/tests/errmsgs/tsimpletypecheck.nim @@ -0,0 +1,10 @@ +discard """ + errormsg: "type mismatch: got <bool> but expected \'string\'" + file: "tsimpletypecheck.nim" + line: 10 +""" +# Test 2 +# Simple type checking + +var a: string +a = false #ERROR diff --git a/tests/errmsgs/tstaticexprnotype.nim b/tests/errmsgs/tstaticexprnotype.nim new file mode 100644 index 000000000..8b6735ff8 --- /dev/null +++ b/tests/errmsgs/tstaticexprnotype.nim @@ -0,0 +1,5 @@ +discard """ + action: reject +""" + +let x = static: discard diff --git a/tests/errmsgs/tstaticexprscope.nim b/tests/errmsgs/tstaticexprscope.nim new file mode 100644 index 000000000..6969e389e --- /dev/null +++ b/tests/errmsgs/tstaticexprscope.nim @@ -0,0 +1,11 @@ +discard """ + errormsg: "undeclared identifier: 'z'" + line: 11 +""" + +# Open a new scope for static expr blocks +block: + let a = static: + var z = 123 + 33 + echo z diff --git a/tests/errmsgs/tstaticresult.nim b/tests/errmsgs/tstaticresult.nim new file mode 100644 index 000000000..bc534c7a8 --- /dev/null +++ b/tests/errmsgs/tstaticresult.nim @@ -0,0 +1,10 @@ +discard """ +errormsg: ''' +invalid type: 'static[int]' in this context: 'proc (x: int): static[int]' for proc +''' +""" + +proc foo(x: int): static int = + x + 123 + +echo foo(123) diff --git a/tests/errmsgs/tsubscriptmismatch.nim b/tests/errmsgs/tsubscriptmismatch.nim new file mode 100644 index 000000000..a2b297b68 --- /dev/null +++ b/tests/errmsgs/tsubscriptmismatch.nim @@ -0,0 +1,11 @@ +discard """ + matrix: "-d:testsConciseTypeMismatch" + nimout: ''' +[1] proc `[]`[T; U, V: Ordinal](s: openArray[T]; x: HSlice[U, V]): seq[T] +''' +""" + +type Foo = object +let x = Foo() +discard x[1] #[tt.Error + ^ type mismatch]# diff --git a/tests/errmsgs/tsubscriptmismatch_legacy.nim b/tests/errmsgs/tsubscriptmismatch_legacy.nim new file mode 100644 index 000000000..3e1f1eb71 --- /dev/null +++ b/tests/errmsgs/tsubscriptmismatch_legacy.nim @@ -0,0 +1,10 @@ +discard """ + nimout: ''' + but expression 'x' is of type: Foo +''' +""" + +type Foo = object +let x = Foo() +discard x[1] #[tt.Error + ^ type mismatch: got <Foo, int literal(1)>]# diff --git a/tests/errmsgs/ttupleindexoutofbounds.nim b/tests/errmsgs/ttupleindexoutofbounds.nim new file mode 100644 index 000000000..ae634dddb --- /dev/null +++ b/tests/errmsgs/ttupleindexoutofbounds.nim @@ -0,0 +1,2 @@ +let a = (1, 2)[4] #[tt.Error + ^ invalid index 4 in subscript for tuple of length 2]# diff --git a/tests/errmsgs/ttypeAllowed.nim b/tests/errmsgs/ttypeAllowed.nim new file mode 100644 index 000000000..fdb4c70b8 --- /dev/null +++ b/tests/errmsgs/ttypeAllowed.nim @@ -0,0 +1,28 @@ +discard """ +cmd: "nim check $file" +errormsg: "" +nimout: ''' +ttypeAllowed.nim(13, 5) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe.}' for let +ttypeAllowed.nim(17, 7) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe.}' for const +ttypeAllowed.nim(21, 5) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe.}' for var +ttypeAllowed.nim(26, 10) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe.}' for result +''' +""" + + +let f1 = case true + of true: countup[int] + of false: countdown[int] + +const f2 = case true + of true: countup[int] + of false: countdown[int] + +var f3 = case true + of true: countup[int] + of false: countdown[int] + +proc foobar(): auto = + result = case true + of true: countup[int] + of false: countdown[int] diff --git a/tests/errmsgs/tuncheckedarrayvar.nim b/tests/errmsgs/tuncheckedarrayvar.nim new file mode 100644 index 000000000..9376a0150 --- /dev/null +++ b/tests/errmsgs/tuncheckedarrayvar.nim @@ -0,0 +1,7 @@ +discard """ +errormsg: ''' +invalid type: 'UncheckedArray[uint8]' for var +''' +""" + +var byteUA: UncheckedArray[uint8] diff --git a/tests/errmsgs/tundeclared_field.nim b/tests/errmsgs/tundeclared_field.nim new file mode 100644 index 000000000..5668050e0 --- /dev/null +++ b/tests/errmsgs/tundeclared_field.nim @@ -0,0 +1,50 @@ +discard """ +cmd: '''nim check --hints:off $file''' +action: reject +nimout: ''' +tundeclared_field.nim(25, 12) Error: undeclared field: 'bad1' for type tundeclared_field.A [type declared in tundeclared_field.nim(22, 8)] +tundeclared_field.nim(30, 17) Error: undeclared field: 'bad2' for type tundeclared_field.A [type declared in tundeclared_field.nim(28, 8)] +tundeclared_field.nim(36, 4) Error: undeclared field: 'bad3' for type tundeclared_field.A [type declared in tundeclared_field.nim(33, 8)] +tundeclared_field.nim(42, 12) Error: undeclared field: 'bad4' for type tundeclared_field.B [type declared in tundeclared_field.nim(39, 8)] +tundeclared_field.nim(43, 4) Error: undeclared field: 'bad5' for type tundeclared_field.B [type declared in tundeclared_field.nim(39, 8)] +tundeclared_field.nim(44, 23) Error: undeclared field: 'bad6' for type tundeclared_field.B [type declared in tundeclared_field.nim(39, 8)] +tundeclared_field.nim(46, 19) Error: undeclared field: 'bad7' for type tundeclared_field.B [type declared in tundeclared_field.nim(39, 8)] +tundeclared_field.nim(50, 13) Error: cannot instantiate Foo [type declared in tundeclared_field.nim(49, 8)] +''' +""" + +#[ +xxx in future work, generic instantiations (e.g. `B[int]`) should be shown with their instantiation instead of `tundeclared_field.B`, +maybe using TPreferedDesc.preferResolved or preferMixed +]# +# line 20 +block: + type A = object + a0: int + var a: A + discard a.bad1 + +block: + type A = object + a0: int + var a = A(bad2: 0) + +block: + type A = object + a0: int + var a: A + a.bad3 = 0 + +block: + type B[T] = object + b0: int + var b: B[int] + discard b.bad4 + b.bad5 = 0 + var b2 = B[int](bad6: 0) + type Bi = B[int] + var b3 = Bi(bad7: 0) + +block: + type Foo[T: SomeInteger] = object + var a: Foo[float] diff --git a/tests/errmsgs/tundeclared_routine.nim b/tests/errmsgs/tundeclared_routine.nim new file mode 100644 index 000000000..41b1d35f4 --- /dev/null +++ b/tests/errmsgs/tundeclared_routine.nim @@ -0,0 +1,44 @@ +discard """ +cmd: '''nim check --hints:off $file''' +action: reject +nimout: ''' +tundeclared_routine.nim(24, 17) Error: attempting to call routine: 'myiter' + found tundeclared_routine.myiter(a: string) [iterator declared in tundeclared_routine.nim(22, 12)] + found tundeclared_routine.myiter() [iterator declared in tundeclared_routine.nim(23, 12)] +tundeclared_routine.nim(29, 28) Error: invalid pragma: myPragma +tundeclared_routine.nim(36, 13) Error: undeclared field: 'bar3' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(33, 8)] + found tundeclared_routine.bar3() [iterator declared in tundeclared_routine.nim(35, 12)] +tundeclared_routine.nim(41, 13) Error: undeclared field: 'bar4' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(39, 8)] +tundeclared_routine.nim(44, 11) Error: undeclared identifier: 'bad5' +''' +""" + + + + + +# line 20 +block: + iterator myiter(a:string): int = discard + iterator myiter(): int = discard + let a = myiter(1) + +block: + proc myPragma():int=discard + iterator myPragma():int=discard + proc myfun(a:int): int {.myPragma.} = 1 + let a = myfun(1) + +block: + type Foo = object + var a = Foo() + iterator bar3():int=discard + let a2 = a.bar3 + +block: + type Foo = object + var a = Foo() + let a2 = a.bar4 + +block: + let a = bad5(1) diff --git a/tests/errmsgs/tundeclared_routine_compiles.nim b/tests/errmsgs/tundeclared_routine_compiles.nim new file mode 100644 index 000000000..21daf82bf --- /dev/null +++ b/tests/errmsgs/tundeclared_routine_compiles.nim @@ -0,0 +1,11 @@ +# D20180828T234921:here +template foo*(iter: untyped): untyped = + when compiles(iter.unexistingField): 0 + elif compiles(iter.len): 1 + else: 2 + +proc foo[A]()= + let a2 = @[10, 11] + let a3 = foo(pairs(a2)) + +foo[int]() diff --git a/tests/errmsgs/tunknown_named_parameter.nim b/tests/errmsgs/tunknown_named_parameter.nim new file mode 100644 index 000000000..d3dd6cd2d --- /dev/null +++ b/tests/errmsgs/tunknown_named_parameter.nim @@ -0,0 +1,27 @@ +discard """ +cmd: "nim check $file" +errormsg: "type mismatch: got <string, set[char], maxsplits: int literal(1)>" +nimout: ''' +func rsplit(s: string; sep: char; maxsplit: int = -1): seq[string] + first type mismatch at position: 2 + required type for sep: char + but expression '{':'}' is of type: set[char] +func rsplit(s: string; sep: string; maxsplit: int = -1): seq[string] + first type mismatch at position: 2 + required type for sep: string + but expression '{':'}' is of type: set[char] +func rsplit(s: string; seps: set[char] = Whitespace; maxsplit: int = -1): seq[ + string] + first type mismatch at position: 3 + unknown named parameter: maxsplits + +expression: rsplit("abc:def", {':'}, maxsplits = 1) +''' +""" + + +# bug #8043 + + +import strutils +"abc:def".rsplit({':'}, maxsplits = 1) diff --git a/tests/errmsgs/tunresolvedinnerproc.nim b/tests/errmsgs/tunresolvedinnerproc.nim new file mode 100644 index 000000000..7655a5a41 --- /dev/null +++ b/tests/errmsgs/tunresolvedinnerproc.nim @@ -0,0 +1,10 @@ +proc wrap[T]() = + proc notConcrete[T](x, y: int): int = + var dummy: T + result = x - y + + var x: proc (x, y: T): int + x = notConcrete #[tt.Error + ^ 'notConcrete' doesn't have a concrete type, due to unspecified generic parameters.]# + +wrap[int]() diff --git a/tests/errmsgs/tuntypedoverload.nim b/tests/errmsgs/tuntypedoverload.nim new file mode 100644 index 000000000..1b1c2809c --- /dev/null +++ b/tests/errmsgs/tuntypedoverload.nim @@ -0,0 +1,37 @@ +discard """ + cmd: "nim check $file" +""" + +block: + template foo(x: var int, y: untyped) = discard + var a: float + foo(a, undeclared) #[tt.Error + ^ type mismatch: got <float, untyped>]# # `untyped` is arbitary + # previous error: undeclared identifier: 'undeclared' + +block: # issue #8697 + type + Fruit = enum + apple + banana + orange + macro hello(x, y: untyped) = discard + hello(apple, banana, orange) #[tt.Error + ^ type mismatch: got <Fruit, Fruit, Fruit>]# + +block: # issue #23265 + template declareFoo(fooName: untyped, value: uint16) = + const `fooName Value` {.inject.} = value + + declareFoo(FOO, 0xFFFF) + declareFoo(BAR, 0xFFFFF) #[tt.Error + ^ type mismatch: got <untyped, int literal(1048575)>]# + +block: # issue #9620 + template forLoop(index: untyped, length: int{lvalue}, body: untyped) = + for `index`{.inject.} in 0 ..< length: + body + var x = newSeq[int](10) + forLoop(i, x.len): #[tt.Error + ^ type mismatch: got <untyped, int, void>]# + x[i] = i diff --git a/tests/errmsgs/twrong_at_operator.nim b/tests/errmsgs/twrong_at_operator.nim index b6b3d101f..438186f01 100644 --- a/tests/errmsgs/twrong_at_operator.nim +++ b/tests/errmsgs/twrong_at_operator.nim @@ -1,14 +1,20 @@ discard """ -errormsg: "type mismatch: got <array[0..0, type int]>" -line: 15 +errormsg: "type mismatch: got <array[0..0, typedesc[int]]>" nimout: ''' -twrong_at_operator.nim(15, 30) Error: type mismatch: got <array[0..0, type int]> +twrong_at_operator.nim(21, 30) Error: type mismatch: got <array[0..0, typedesc[int]]> but expected one of: +proc `@`[IDX, T](a: sink array[IDX, T]): seq[T] + first type mismatch at position: 1 + required type for a: sink array[IDX, T] + but expression '[int]' is of type: array[0..0, typedesc[int]] proc `@`[T](a: openArray[T]): seq[T] -proc `@`[IDX, T](a: array[IDX, T]): seq[T] + first type mismatch at position: 1 + required type for a: openArray[T] + but expression '[int]' is of type: array[0..0, typedesc[int]] expression: @[int] ''' +disabled: "32bit" """ # bug #7331 diff --git a/tests/errmsgs/twrong_explicit_typeargs.nim b/tests/errmsgs/twrong_explicit_typeargs.nim new file mode 100644 index 000000000..5236e5f4f --- /dev/null +++ b/tests/errmsgs/twrong_explicit_typeargs.nim @@ -0,0 +1,26 @@ +discard """ + cmd: "nim c --hints:off -d:testsConciseTypeMismatch $file" + action: reject + nimout: ''' +twrong_explicit_typeargs.nim(26, 29) Error: type mismatch +Expression: newImage[string](320, 200) + [1] 320: int literal(320) + [2] 200: int literal(200) + +Expected one of (first mismatch at [position]): +[1] proc newImage[T: int32 | int64](w, h: int): ref Image[T] + generic parameter mismatch, expected int32 or int64 but got 'string' of type: string +''' +""" + +# bug #4084 +type + Image[T] = object + data: seq[T] + +proc newImage[T: int32|int64](w, h: int): ref Image[T] = + new(result) + result.data = newSeq[T](w * h) + +var correct = newImage[int32](320, 200) +var wrong = newImage[string](320, 200) diff --git a/tests/errmsgs/twrong_explicit_typeargs_legacy.nim b/tests/errmsgs/twrong_explicit_typeargs_legacy.nim new file mode 100644 index 000000000..cfa528c54 --- /dev/null +++ b/tests/errmsgs/twrong_explicit_typeargs_legacy.nim @@ -0,0 +1,25 @@ +discard """ + action: reject + nimout: ''' +twrong_explicit_typeargs_legacy.nim(25, 29) Error: type mismatch: got <int literal(320), int literal(200)> +but expected one of: +proc newImage[T: int32 | int64](w, h: int): ref Image[T] + first type mismatch at position: 1 in generic parameters + required type for T: int32 or int64 + but expression 'string' is of type: string + +expression: newImage[string](320, 200) +''' +""" + +# bug #4084 +type + Image[T] = object + data: seq[T] + +proc newImage[T: int32|int64](w, h: int): ref Image[T] = + new(result) + result.data = newSeq[T](w * h) + +var correct = newImage[int32](320, 200) +var wrong = newImage[string](320, 200) diff --git a/tests/errmsgs/twrongcolon.nim b/tests/errmsgs/twrongcolon.nim index 6f5cc3e5d..06e802eb7 100644 --- a/tests/errmsgs/twrongcolon.nim +++ b/tests/errmsgs/twrongcolon.nim @@ -1,11 +1,10 @@ discard """ -errormsg: "in expression '(" +errormsg: "in expression ' do:" nimout: ''' -Error: in expression '( - 890)': identifier expected, but found '' +twrongcolon.nim(10, 12) Error: in expression ' do: + 890': identifier expected, but found '' ''' -line: 11 """ var n: int : 890 |