diff options
Diffstat (limited to 'tests/errmsgs')
96 files changed, 1303 insertions, 195 deletions
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 index 2ce16d6a2..814c860dc 100644 --- a/tests/errmsgs/t10376.nim +++ b/tests/errmsgs/t10376.nim @@ -1,6 +1,7 @@ discard """ + matrix: "--mm:refc" errormsg: "finalizer must be a direct reference to a proc" - line: 29 + line: 30 """ type diff --git a/tests/errmsgs/t10489_a.nim b/tests/errmsgs/t10489_a.nim index 71a6cc3c4..c762ce876 100644 --- a/tests/errmsgs/t10489_a.nim +++ b/tests/errmsgs/t10489_a.nim @@ -1,5 +1,5 @@ discard """ -errormsg: "invalid type: 'macro (body: untyped): untyped{.noSideEffect, gcsafe, locks: 0.}' for let. Did you mean to call the macro with '()'?" +errormsg: "invalid type: 'macro (body: untyped): untyped{.noSideEffect, gcsafe.}' for let. Did you mean to call the macro with '()'?" line: 9 """ diff --git a/tests/errmsgs/t10489_b.nim b/tests/errmsgs/t10489_b.nim index 4b0b876e5..df05f0e6e 100644 --- a/tests/errmsgs/t10489_b.nim +++ b/tests/errmsgs/t10489_b.nim @@ -1,5 +1,5 @@ discard """ -errormsg: "invalid type: 'macro (body: untyped): untyped{.noSideEffect, gcsafe, locks: 0.}' for const. Did you mean to call the macro with '()'?" +errormsg: "invalid type: 'macro (body: untyped): untyped{.noSideEffect, gcsafe.}' for const. Did you mean to call the macro with '()'?" line: 9 """ 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 index c9506c542..d27dd6433 100644 --- a/tests/errmsgs/t10594.nim +++ b/tests/errmsgs/t10594.nim @@ -3,5 +3,5 @@ discard """ line: 7 """ -template foo(v: varargs[int]) = unsafeAddr v +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/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 a9e260845..dea7e40b3 100644 --- a/tests/errmsgs/t5167_5.nim +++ b/tests/errmsgs/t5167_5.nim @@ -1,13 +1,9 @@ discard """ -cmd: "nim check $file" -errormsg: "'t' has unspecified generic parameters" -nimout: ''' -t5167_5.nim(10, 16) Error: expression 'system' has no type (or is ambiguous) -t5167_5.nim(21, 9) Error: 't' has unspecified generic parameters -''' +cmd: "nim check --mm:refc $file" """ # issue #11942 -discard newSeq[system]() +discard newSeq[system]() #[tt.Error + ^ expression 'system' has no type (or is ambiguous)]# # issue #5167 template t[B]() = @@ -18,8 +14,12 @@ macro m[T]: untyped = nil proc bar(x: proc (x: int)) = echo "bar" -let x = t -bar t +let x = t #[tt.Error + ^ 't' has unspecified generic parameters]# +bar t #[tt.Error +^ type mismatch: got <template [*missing parameters*]()>]# -let y = m -bar m +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/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/t8610.nim b/tests/errmsgs/t8610.nim index 6a253f7ab..ec99beae5 100644 --- a/tests/errmsgs/t8610.nim +++ b/tests/errmsgs/t8610.nim @@ -1,5 +1,5 @@ discard """ - errmsg: "invalid type: 'type int' for const" + errormsg: "invalid type: 'typedesc[int]' for const" """ -## issue #8610 +## bug #8610 const Foo = int diff --git a/tests/errmsgs/t8794.nim b/tests/errmsgs/t8794.nim index 22e4014f1..36f05dbad 100644 --- a/tests/errmsgs/t8794.nim +++ b/tests/errmsgs/t8794.nim @@ -1,33 +1,16 @@ discard """ cmd: "nim check $options $file" - errormsg: "" - nimout: ''' -t8794.nim(39, 27) Error: undeclared field: 'a3' for type m8794.Foo3 [declared in m8794.nim(1, 6)] -''' """ - - - - - - - - - - - -## line 20 - ## issue #8794 import m8794 -when false: # pending https://github.com/nim-lang/Nim/pull/10091 add this - type Foo = object - a1: int +type Foo = object + a1: int - discard Foo().a2 +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 @@ -36,4 +19,5 @@ proc getFun[T](): T = var a: T a -discard getFun[type(x2)]().a3 +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 index d369150a5..b5ff58367 100644 --- a/tests/errmsgs/t9768.nim +++ b/tests/errmsgs/t9768.nim @@ -1,13 +1,14 @@ discard """ - errmsg: "unhandled exception:" - file: "system/fatal.nim" + 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(28, 33) main -t9768.nim(23, 11) foo1 +t9768.nim(29, 33) main +t9768.nim(24, 11) foo1 ''' """ - +import std/assertions diff --git a/tests/errmsgs/t9908_01.nim b/tests/errmsgs/t9908_01.nim index b9d37b67b..99bc8237d 100644 --- a/tests/errmsgs/t9908_01.nim +++ b/tests/errmsgs/t9908_01.nim @@ -1,5 +1,5 @@ discard """ -errormsg: "ordinal type expected" +errormsg: "ordinal type expected; given: string" line: 10 """ diff --git a/tests/errmsgs/t9908_02.nim b/tests/errmsgs/t9908_02.nim index 7ff3d1ff7..4fc60b3df 100644 --- a/tests/errmsgs/t9908_02.nim +++ b/tests/errmsgs/t9908_02.nim @@ -1,5 +1,5 @@ discard """ -errormsg: "ordinal type expected" +errormsg: "ordinal type expected; given: float" line: 10 """ 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 index 1cc86638f..44752f1ee 100644 --- a/tests/errmsgs/tcall_with_default_arg.nim +++ b/tests/errmsgs/tcall_with_default_arg.nim @@ -1,5 +1,5 @@ discard """ -outputsub: '''tcall_with_default_arg.nim(16) anotherFoo''' +outputsub: '''tcall_with_default_arg.nim(8) fail''' exitcode: 1 """ # issue: #5604 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/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/tgcsafety.nim b/tests/errmsgs/tgcsafety.nim index e6a62204e..66496d364 100644 --- a/tests/errmsgs/tgcsafety.nim +++ b/tests/errmsgs/tgcsafety.nim @@ -1,15 +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] {.closure, gcsafe.}; - address = ""): owned(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 for callback: proc (request: Request): Future[system.void]{.closure, gcsafe.} - but expression 'cb' is of type: proc (req: Request): Future[system.void]{.locks: <unknown>.} + 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/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 index 98c92a227..f90ab14a1 100644 --- a/tests/errmsgs/tinteger_literals.nim +++ b/tests/errmsgs/tinteger_literals.nim @@ -1,15 +1,14 @@ discard """ -cmd: "nim check $file" -errormsg: "number out of range: '300'u8'" -nimout: ''' -tinteger_literals.nim(12, 9) Error: number out of range: '18446744073709551616'u64' -tinteger_literals.nim(13, 9) Error: number out of range: '9223372036854775808'i64' -tinteger_literals.nim(14, 9) Error: number out of range: '9223372036854775808' -tinteger_literals.nim(15, 9) Error: number out of range: '300'u8' -''' + cmd: "nim check $file" """ - -discard 18446744073709551616'u64 # high(uint64) + 1 -discard 9223372036854775808'i64 # high(int64) + 1 -discard 9223372036854775808 # high(int64) + 1 -discard 300'u8 \ No newline at end of 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/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/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 c7dfbaf2a..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 @@ -76,10 +77,10 @@ when true: 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 true: 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 true: 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 true: 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 index b339e06bf..46afe163d 100644 --- a/tests/errmsgs/treportunused.nim +++ b/tests/errmsgs/treportunused.nim @@ -1,16 +1,28 @@ discard """ + matrix: "--hint:all:off --hint:XDeclaredButNotUsed" + nimoutFull: true nimout: ''' -treportunused.nim(19, 10) Hint: 's1' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(26, 5) Hint: 's8' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(22, 6) Hint: 's4' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(25, 7) Hint: 's7' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(24, 7) Hint: 's6' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(23, 6) Hint: 's5' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(20, 10) Hint: 's2' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(29, 6) Hint: 's11' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(27, 5) Hint: 's9' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(21, 10) Hint: 's3' is declared but not used [XDeclaredButNotUsed] -treportunused.nim(28, 6) Hint: 's10' is declared but not used [XDeclaredButNotUsed] +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 """ @@ -27,3 +39,27 @@ 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/tsigmatch.nim b/tests/errmsgs/tsigmatch.nim index 4f40be2d4..85ed34169 100644 --- a/tests/errmsgs/tsigmatch.nim +++ b/tests/errmsgs/tsigmatch.nim @@ -1,5 +1,5 @@ discard """ - cmd: "nim check --showAllMismatches:on --hints:off $file" + 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: @@ -12,34 +12,34 @@ proc f(b: B) but expression 'A()' is of type: A expression: f(A(), "extra") -tsigmatch.nim(125, 6) Error: type mismatch: got <(string, proc (){.gcsafe, locks: 0.})> +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, locks: 0.}) + 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, locks: 0.}> +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, locks: 0.} + 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, locks: 0.} + 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, locks: 0.}]> +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, locks: 0.}]) +proc takesFuncs(fs: openArray[proc (x: int) {.gcsafe.}]) first type mismatch at position: 1 - required type for fs: openArray[proc (x: int){.closure, gcsafe, locks: 0.}] - but expression '[proc (x: int) {.gcsafe, locks: 0.} = echo [x]]' is of type: array[0..0, proc (x: int){.gcsafe, locks: 0.}] + 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, locks: 0.} = echo [x]]) +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) @@ -89,9 +89,9 @@ expression: fun1(default(Mystring), "asdf") - - - +#[ +see also: tests/errmsgs/tdeclaredlocs.nim +]# @@ -132,15 +132,15 @@ block: echo foo(fun) block: - # bug #10285 Function signature don't match when inside seq/array/openarray + # 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, locks: 0.}) = + proc takesFunc(f: proc (x: int) {.gcsafe.}) = echo "takes single Func" - proc takesFuncs(fs: openarray[proc (x: int) {.gcsafe, locks: 0.}]) = + proc takesFuncs(fs: openArray[proc (x: int) {.gcsafe.}]) = echo "takes multiple Func" - takesFunc(proc (x: int) {.gcsafe, locks: 0.} = echo x) # works - takesFuncs([proc (x: int) {.gcsafe, locks: 0.} = echo x]) # fails + 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 diff --git a/tests/errmsgs/tsigmatch2.nim b/tests/errmsgs/tsigmatch2.nim index 4996634c9..31c966337 100644 --- a/tests/errmsgs/tsigmatch2.nim +++ b/tests/errmsgs/tsigmatch2.nim @@ -14,7 +14,7 @@ proc foo(i: Foo): string expression: foo(1.2) tsigmatch2.nim(40, 14) Error: expression '' has no type (or is ambiguous) -tsigmatch2.nim(46, 7) Error: type mismatch: got <int literal(1)> +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 @@ -44,4 +44,4 @@ block: let temp = 12.isNil proc foo(args: varargs[string, myproc]) = discard foo 1 -static: echo "done" \ No newline at end of file +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/tstaticexprscope.nim b/tests/errmsgs/tstaticexprscope.nim index 7af5bf9b3..6969e389e 100644 --- a/tests/errmsgs/tstaticexprscope.nim +++ b/tests/errmsgs/tstaticexprscope.nim @@ -1,5 +1,5 @@ discard """ - errmsg: "undeclared identifier: 'z'" + errormsg: "undeclared identifier: 'z'" line: 11 """ 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 index 9efbc6ead..fdb4c70b8 100644 --- a/tests/errmsgs/ttypeAllowed.nim +++ b/tests/errmsgs/ttypeAllowed.nim @@ -1,11 +1,11 @@ discard """ cmd: "nim check $file" -errmsg: "" +errormsg: "" nimout: ''' -ttypeAllowed.nim(13, 5) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe, locks: 0.}' for let -ttypeAllowed.nim(17, 7) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe, locks: 0.}' for const -ttypeAllowed.nim(21, 5) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe, locks: 0.}' for var -ttypeAllowed.nim(26, 10) Error: invalid type: 'iterator (a: int, b: int, step: Positive): int{.inline, noSideEffect, gcsafe, locks: 0.}' for result +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 ''' """ 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/undeclared_routime_compiles.nim b/tests/errmsgs/tundeclared_routine_compiles.nim index 21daf82bf..21daf82bf 100644 --- a/tests/errmsgs/undeclared_routime_compiles.nim +++ b/tests/errmsgs/tundeclared_routine_compiles.nim diff --git a/tests/errmsgs/tunknown_named_parameter.nim b/tests/errmsgs/tunknown_named_parameter.nim index b139310db..d3dd6cd2d 100644 --- a/tests/errmsgs/tunknown_named_parameter.nim +++ b/tests/errmsgs/tunknown_named_parameter.nim @@ -2,15 +2,16 @@ discard """ cmd: "nim check $file" errormsg: "type mismatch: got <string, set[char], maxsplits: int literal(1)>" nimout: ''' -proc rsplit(s: string; sep: char; maxsplit: int = -1): seq[string] +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] -proc rsplit(s: string; sep: string; maxsplit: int = -1): seq[string] +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] -proc rsplit(s: string; seps: set[char] = Whitespace; maxsplit: int = -1): seq[string] +func rsplit(s: string; seps: set[char] = Whitespace; maxsplit: int = -1): seq[ + string] first type mismatch at position: 3 unknown named parameter: maxsplits @@ -22,6 +23,5 @@ 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 ebf6d966b..438186f01 100644 --- a/tests/errmsgs/twrong_at_operator.nim +++ b/tests/errmsgs/twrong_at_operator.nim @@ -1,17 +1,16 @@ discard """ -errormsg: "type mismatch: got <array[0..0, type int]>" -line: 22 +errormsg: "type mismatch: got <array[0..0, typedesc[int]]>" nimout: ''' -twrong_at_operator.nim(22, 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, type int] + but expression '[int]' is of type: array[0..0, typedesc[int]] proc `@`[T](a: openArray[T]): seq[T] first type mismatch at position: 1 required type for a: openArray[T] - but expression '[int]' is of type: array[0..0, type int] + but expression '[int]' is of type: array[0..0, typedesc[int]] expression: @[int] ''' 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 e59e37660..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 ': +twrongcolon.nim(10, 12) Error: in expression ' do: 890': identifier expected, but found '' ''' -line: 11 """ var n: int : 890 diff --git a/tests/errmsgs/undeclared_routime.nim b/tests/errmsgs/undeclared_routime.nim deleted file mode 100644 index 426507652..000000000 --- a/tests/errmsgs/undeclared_routime.nim +++ /dev/null @@ -1,13 +0,0 @@ -discard """ -cmd: '''nim c --hints:off $file''' -errormsg: "attempting to call routine: 'myiter'" -nimout: '''undeclared_routime.nim(13, 15) Error: attempting to call routine: 'myiter' - found 'undeclared_routime.myiter(a: string)[declared in undeclared_routime.nim(10, 9)]' of kind 'iterator' - found 'undeclared_routime.myiter()[declared in undeclared_routime.nim(11, 9)]' of kind 'iterator' -''' -""" - -iterator myiter(a:string): int = discard -iterator myiter(): int = discard - -let a = myiter(1) diff --git a/tests/errmsgs/undeclared_routime2.nim b/tests/errmsgs/undeclared_routime2.nim deleted file mode 100644 index 3e48b48f4..000000000 --- a/tests/errmsgs/undeclared_routime2.nim +++ /dev/null @@ -1,9 +0,0 @@ -discard """ -cmd: '''nim c --hints:off $file''' -errormsg: "invalid pragma: myPragma" -""" - -proc myPragma():int=discard -iterator myPragma():int=discard -proc myfun(a:int): int {.myPragma.} = 1 -let a = myfun(1) diff --git a/tests/errmsgs/undeclared_routime3.nim b/tests/errmsgs/undeclared_routime3.nim deleted file mode 100644 index 052adfc08..000000000 --- a/tests/errmsgs/undeclared_routime3.nim +++ /dev/null @@ -1,13 +0,0 @@ -discard """ -cmd: '''nim c --hints:off $file''' -errormsg: "undeclared field: 'bar'" -nimout: '''undeclared_routime3.nim(13, 10) Error: undeclared field: 'bar' - found 'undeclared_routime3.bar()[declared in undeclared_routime3.nim(12, 9)]' of kind 'iterator' -''' -""" - - -type Foo = object -var a = Foo() -iterator bar():int=discard -let a = a.bar diff --git a/tests/errmsgs/undeclared_routime4.nim b/tests/errmsgs/undeclared_routime4.nim deleted file mode 100644 index 674caa421..000000000 --- a/tests/errmsgs/undeclared_routime4.nim +++ /dev/null @@ -1,10 +0,0 @@ -discard """ -cmd: '''nim c --hints:off $file''' -errormsg: "undeclared field: 'bar'" -nimout: '''undeclared_routime4.nim(10, 10) Error: undeclared field: 'bar' -''' -""" - -type Foo = object -var a = Foo() -let a = a.bar diff --git a/tests/errmsgs/undeclared_routime5.nim b/tests/errmsgs/undeclared_routime5.nim deleted file mode 100644 index 4394134ab..000000000 --- a/tests/errmsgs/undeclared_routime5.nim +++ /dev/null @@ -1,9 +0,0 @@ -discard """ -cmd: '''nim c --hints:off $file''' -errormsg: "undeclared identifier: 'myfun'" -nimout: '''undeclared_routime5.nim(9, 9) Error: undeclared identifier: 'myfun' -''' -""" - - -let a = myfun(1) |