From ef6eda4cb4b28a6c4a2706ea56240bc708e36349 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 10 Feb 2018 20:39:05 +0100 Subject: better error messages: use instead of (T1, T2) in order to prevent confusions with tuple types --- compiler/msgs.nim | 2 +- compiler/semcall.nim | 8 ++--- compiler/semexprs.nim | 2 +- compiler/semtypes.nim | 4 +-- compiler/types.nim | 2 +- tests/array/tarrayplus.nim | 2 +- tests/concepts/t3330.nim | 46 +++++++++++++-------------- tests/concepts/texplain.nim | 8 ++--- tests/concepts/twrapconcept.nim | 4 +-- tests/errmsgs/t4756.nim | 2 +- tests/errmsgs/t5167_4.nim | 2 +- tests/errmsgs/tconceptconstraint.nim | 6 ++-- tests/errmsgs/tdetailed_position.nim | 8 ++--- tests/errmsgs/tgenericconstraint.nim | 4 +-- tests/errmsgs/tmake_tuple_visible.nim | 4 +-- tests/errmsgs/tshow_asgn.nim | 2 +- tests/metatype/tvoid_must_not_match.nim | 2 +- tests/overload/tissue966.nim | 2 +- tests/typerel/temptynode.nim | 2 +- tests/typerel/tgeneric_subtype_regression.nim | 2 +- tests/typerel/tno_int_in_bool_context.nim | 2 +- tests/typerel/tnocontains.nim | 2 +- tests/typerel/tregionptrs.nim | 2 +- tests/typerel/ttypedesc_as_genericparam1.nim | 2 +- tests/typerel/ttypenoval.nim | 2 +- 25 files changed, 62 insertions(+), 62 deletions(-) diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 954883b01..6439d47ee 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -272,7 +272,7 @@ const errXStackEscape: "address of '$1' may not escape its stack frame", errVarForOutParamNeededX: "for a \'var\' type a variable needs to be passed; but '$1' is immutable", errPureTypeMismatch: "type mismatch", - errTypeMismatch: "type mismatch: got (", + errTypeMismatch: "type mismatch: got <", errButExpected: "but expected one of: ", errButExpectedX: "but expected \'$1\'", errAmbiguousCallXYZ: "ambiguous call; both $1 and $2 match for: $3", diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 01f291017..d8ee6e7a1 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -156,14 +156,14 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors): add(candidates, err.sym.getProcHeader(prefer)) add(candidates, "\n") if err.firstMismatch != 0 and n.len > 2: - add(candidates, "first type mismatch at position: " & $err.firstMismatch & - "\nrequired type: ") + add(candidates, " first type mismatch at position: " & $err.firstMismatch & + "\n required type: ") if err.firstMismatch < err.sym.typ.len: candidates.add typeToString(err.sym.typ.sons[err.firstMismatch]) else: candidates.add "none" if err.firstMismatch < n.len: - candidates.add "\nbut expression '" + candidates.add "\n but expression '" candidates.add renderTree(n[err.firstMismatch]) candidates.add "' is of type: " candidates.add typeToString(n[err.firstMismatch].typ) @@ -190,7 +190,7 @@ proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) = let (prefer, candidates) = presentFailedCandidates(c, n, errors) var result = msgKindToString(errTypeMismatch) add(result, describeArgs(c, n, 1, prefer)) - add(result, ')') + add(result, '>') if candidates != "": add(result, "\n" & msgKindToString(errButExpected) & "\n" & candidates) localError(n.info, errGenerated, result & "\nexpression: " & $n) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index d4b1eec88..7f58e266e 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -735,7 +735,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode = hasErrorType = true break if not hasErrorType: - add(msg, ")\n" & msgKindToString(errButExpected) & "\n" & + add(msg, ">\n" & msgKindToString(errButExpected) & "\n" & typeToString(n.sons[0].typ)) localError(n.info, errGenerated, msg) return errorNode(c, n) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index f14b40a9b..df274c7db 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1149,8 +1149,8 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType = if m.state != csMatch: let err = "cannot instantiate " & typeToString(t) & "\n" & - "got: (" & describeArgs(c, n) & ")\n" & - "but expected: (" & describeArgs(c, t.n, 0) & ")" + "got: <" & describeArgs(c, n) & ">\n" & + "but expected: <" & describeArgs(c, t.n, 0) & ">" localError(n.info, errGenerated, err) return newOrPrevType(tyError, prev, c) diff --git a/compiler/types.nim b/compiler/types.nim index 452e95dfd..10827f830 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1620,7 +1620,7 @@ proc typeMismatch*(info: TLineInfo, formal, actual: PType) = let desc = typeToString(formal, preferDesc) let x = if named == desc: named else: named & " = " & desc var msg = msgKindToString(errTypeMismatch) & - typeToString(actual) & ") " & + typeToString(actual) & "> " & msgKindToString(errButExpectedX) % [x] if formal.kind == tyProc and actual.kind == tyProc: diff --git a/tests/array/tarrayplus.nim b/tests/array/tarrayplus.nim index 33921c0e1..09bae77fd 100644 --- a/tests/array/tarrayplus.nim +++ b/tests/array/tarrayplus.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "type mismatch: got (array[0..2, float], array[0..1, float])" + errormsg: "type mismatch: got " """ proc `+`*[R, T] (v1, v2: array[R, T]): array[R, T] = diff --git a/tests/concepts/t3330.nim b/tests/concepts/t3330.nim index 6c9883618..a4fff7fb3 100644 --- a/tests/concepts/t3330.nim +++ b/tests/concepts/t3330.nim @@ -1,38 +1,38 @@ discard """ -errormsg: "type mismatch: got (Bar[system.int])" +errormsg: "type mismatch: got " nimout: ''' -t3330.nim(63, 4) Error: type mismatch: got (Bar[system.int]) +t3330.nim(63, 4) Error: type mismatch: got but expected one of: proc test(foo: Foo[int]) t3330.nim(48, 8) Hint: Non-matching candidates for add(k, string, T) proc add(x: var string; y: string) -first type mismatch at position: 1 -required type: var string -but expression 'k' is of type: Alias + first type mismatch at position: 1 + required type: var string + but expression 'k' is of type: Alias proc add(x: var string; y: char) -first type mismatch at position: 1 -required type: var string -but expression 'k' is of type: Alias + first type mismatch at position: 1 + required type: var string + but expression 'k' is of type: Alias proc add(result: var string; x: int64) -first type mismatch at position: 1 -required type: var string -but expression 'k' is of type: Alias + first type mismatch at position: 1 + required type: var string + but expression 'k' is of type: Alias proc add(result: var string; x: float) -first type mismatch at position: 1 -required type: var string -but expression 'k' is of type: Alias + first type mismatch at position: 1 + required type: var string + but expression 'k' is of type: Alias proc add(x: var string; y: cstring) -first type mismatch at position: 1 -required type: var string -but expression 'k' is of type: Alias + first type mismatch at position: 1 + required type: var string + but expression 'k' is of type: Alias proc add[T](x: var seq[T]; y: openArray[T]) -first type mismatch at position: 1 -required type: var seq[T] -but expression 'k' is of type: Alias + first type mismatch at position: 1 + required type: var seq[T] + but expression 'k' is of type: Alias proc add[T](x: var seq[T]; y: T) -first type mismatch at position: 1 -required type: var seq[T] -but expression 'k' is of type: Alias + first type mismatch at position: 1 + required type: var seq[T] + but expression 'k' is of type: Alias t3330.nim(48, 8) template/generic instantiation from here t3330.nim(55, 6) Foo: 'bar.value' cannot be assigned to diff --git a/tests/concepts/texplain.nim b/tests/concepts/texplain.nim index de8ddf890..4925a25b3 100644 --- a/tests/concepts/texplain.nim +++ b/tests/concepts/texplain.nim @@ -26,14 +26,14 @@ texplain.nim(70, 6) ExplainedConcept: undeclared field: '.' texplain.nim(70, 6) ExplainedConcept: expression '.' cannot be called texplain.nim(69, 5) ExplainedConcept: concept predicate failed -texplain.nim(113, 20) Error: type mismatch: got (NonMatchingType) +texplain.nim(113, 20) Error: type mismatch: got but expected one of: proc e(o: ExplainedConcept): int texplain.nim(69, 5) ExplainedConcept: concept predicate failed proc e(i: int): int expression: e(n) -texplain.nim(114, 20) Error: type mismatch: got (NonMatchingType) +texplain.nim(114, 20) Error: type mismatch: got but expected one of: proc r(o: RegularConcept): int texplain.nim(73, 5) RegularConcept: concept predicate failed @@ -45,7 +45,7 @@ texplain.nim(115, 20) Hint: Non-matching candidates for r(y) proc r[T](a: SomeNumber; b: T; c: auto) proc r(i: string): int -texplain.nim(123, 2) Error: type mismatch: got (MatchingType) +texplain.nim(123, 2) Error: type mismatch: got but expected one of: proc f(o: NestedConcept) texplain.nim(73, 6) RegularConcept: undeclared field: 'foo' @@ -61,7 +61,7 @@ texplain.nim(77, 5) NestedConcept: concept predicate failed expression: f(y) ''' line: 123 - errormsg: "type mismatch: got (MatchingType)" + errormsg: "type mismatch: got " """ type diff --git a/tests/concepts/twrapconcept.nim b/tests/concepts/twrapconcept.nim index 25a855e34..377b63afe 100644 --- a/tests/concepts/twrapconcept.nim +++ b/tests/concepts/twrapconcept.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "type mismatch: got (string)" + errormsg: "type mismatch: got " line: 21 nimout: "twrapconcept.nim(11, 5) Foo: concept predicate failed" """ @@ -9,7 +9,7 @@ discard """ type Foo = concept foo foo.get is int - + FooWrap[F: Foo] = object foo: F diff --git a/tests/errmsgs/t4756.nim b/tests/errmsgs/t4756.nim index 91fc90f4b..262614ba0 100644 --- a/tests/errmsgs/t4756.nim +++ b/tests/errmsgs/t4756.nim @@ -1,5 +1,5 @@ discard """ -errormsg: "type mismatch: got (string, arr: seq[empty])" +errormsg: "type mismatch: got " line: 15 """ diff --git a/tests/errmsgs/t5167_4.nim b/tests/errmsgs/t5167_4.nim index 3d77fae02..7a263622b 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 " line: 19 """ diff --git a/tests/errmsgs/tconceptconstraint.nim b/tests/errmsgs/tconceptconstraint.nim index c1f0b94eb..9ab1708c7 100644 --- a/tests/errmsgs/tconceptconstraint.nim +++ b/tests/errmsgs/tconceptconstraint.nim @@ -2,15 +2,15 @@ discard """ errormsg: "cannot instantiate B" line: 20 nimout: ''' -got: (type string) -but expected: (T: A) +got: +but expected: ''' """ type A = concept c advance(c) - + B[T: A] = object child: ref B[T] diff --git a/tests/errmsgs/tdetailed_position.nim b/tests/errmsgs/tdetailed_position.nim index d6db94c3e..ce5b18bbd 100644 --- a/tests/errmsgs/tdetailed_position.nim +++ b/tests/errmsgs/tdetailed_position.nim @@ -1,13 +1,13 @@ discard """ cmd: "nim check $file" -errormsg: "type mismatch: got (int literal(1), int literal(2), int literal(3))" +errormsg: "type mismatch: got " nimout: ''' but expected one of: proc main(a, b, c: string) -first type mismatch at position: 1 -required type: string -but expression '1' is of type: int literal(1) + first type mismatch at position: 1 + required type: string + but expression '1' is of type: int literal(1) expression: main(1, 2, 3) ''' diff --git a/tests/errmsgs/tgenericconstraint.nim b/tests/errmsgs/tgenericconstraint.nim index 9129d257b..e3093fead 100644 --- a/tests/errmsgs/tgenericconstraint.nim +++ b/tests/errmsgs/tgenericconstraint.nim @@ -2,8 +2,8 @@ discard """ errormsg: "cannot instantiate B" line: 14 nimout: ''' -got: (type int) -but expected: (T: string or float) +got: +but expected: ''' """ diff --git a/tests/errmsgs/tmake_tuple_visible.nim b/tests/errmsgs/tmake_tuple_visible.nim index 43337c2a9..e059368ad 100644 --- a/tests/errmsgs/tmake_tuple_visible.nim +++ b/tests/errmsgs/tmake_tuple_visible.nim @@ -1,7 +1,7 @@ discard """ - errormsg: '''got (tuple of (type NimEdAppWindow, int))''' + errormsg: '''got ''' line: 22 - nimout: '''got (tuple of (type NimEdAppWindow, int)) + nimout: '''got but expected one of: template xxx(tn: typedesc; i: int)''' """ diff --git a/tests/errmsgs/tshow_asgn.nim b/tests/errmsgs/tshow_asgn.nim index 250f786e2..1627c9b71 100644 --- a/tests/errmsgs/tshow_asgn.nim +++ b/tests/errmsgs/tshow_asgn.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "type mismatch: got (int) but expected 'cshort = int16'" + errormsg: "type mismatch: got but expected 'cshort = int16'" line: 12 column: 10 file: "tshow_asgn.nim" diff --git a/tests/metatype/tvoid_must_not_match.nim b/tests/metatype/tvoid_must_not_match.nim index 240c3f751..c786c2f16 100644 --- a/tests/metatype/tvoid_must_not_match.nim +++ b/tests/metatype/tvoid_must_not_match.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "type mismatch: got (Future[system.int], void)" + errormsg: "type mismatch: got " line: 20 """ diff --git a/tests/overload/tissue966.nim b/tests/overload/tissue966.nim index 2911348cf..c5b28e217 100644 --- a/tests/overload/tissue966.nim +++ b/tests/overload/tissue966.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "type mismatch: got (PTest)" + errormsg: "type mismatch: got " """ type diff --git a/tests/typerel/temptynode.nim b/tests/typerel/temptynode.nim index 32148ce13..df308fbc2 100644 --- a/tests/typerel/temptynode.nim +++ b/tests/typerel/temptynode.nim @@ -1,6 +1,6 @@ discard """ line: 16 - errormsg: "type mismatch: got (void)" + errormsg: "type mismatch: got " """ # bug #950 diff --git a/tests/typerel/tgeneric_subtype_regression.nim b/tests/typerel/tgeneric_subtype_regression.nim index e279c0ad4..def5d721e 100644 --- a/tests/typerel/tgeneric_subtype_regression.nim +++ b/tests/typerel/tgeneric_subtype_regression.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "type mismatch: got (FooRef[system.string])" + errormsg: "type mismatch: got " line: 15 """ diff --git a/tests/typerel/tno_int_in_bool_context.nim b/tests/typerel/tno_int_in_bool_context.nim index 557759169..a4b4237d2 100644 --- a/tests/typerel/tno_int_in_bool_context.nim +++ b/tests/typerel/tno_int_in_bool_context.nim @@ -1,6 +1,6 @@ discard """ line: 6 - errormsg: "type mismatch: got (int literal(1)) but expected 'bool'" + errormsg: "type mismatch: got but expected 'bool'" """ if 1: diff --git a/tests/typerel/tnocontains.nim b/tests/typerel/tnocontains.nim index 4f4951478..a93db2fc3 100644 --- a/tests/typerel/tnocontains.nim +++ b/tests/typerel/tnocontains.nim @@ -1,7 +1,7 @@ discard """ file: "tnocontains.nim" line: 10 - errormsg: "type mismatch: got (string, string)" + errormsg: "type mismatch: got " """ # shouldn't compile since it doesn't do what you think it does without diff --git a/tests/typerel/tregionptrs.nim b/tests/typerel/tregionptrs.nim index a8d2e7a6d..9eeded18b 100644 --- a/tests/typerel/tregionptrs.nim +++ b/tests/typerel/tregionptrs.nim @@ -1,6 +1,6 @@ discard """ line: 16 - errormsg: "type mismatch: got (BPtr) but expected 'APtr = ptr[RegionA, int]'" + errormsg: "type mismatch: got but expected 'APtr = ptr[RegionA, int]'" """ type diff --git a/tests/typerel/ttypedesc_as_genericparam1.nim b/tests/typerel/ttypedesc_as_genericparam1.nim index 88c0509b2..9ae464842 100644 --- a/tests/typerel/ttypedesc_as_genericparam1.nim +++ b/tests/typerel/ttypedesc_as_genericparam1.nim @@ -1,6 +1,6 @@ discard """ line: 6 - errormsg: "type mismatch: got (type int)" + errormsg: "type mismatch: got " """ # bug #3079, #1146 echo repr(int) diff --git a/tests/typerel/ttypenoval.nim b/tests/typerel/ttypenoval.nim index eabca48f6..720e5d662 100644 --- a/tests/typerel/ttypenoval.nim +++ b/tests/typerel/ttypenoval.nim @@ -1,7 +1,7 @@ discard """ file: "ttypenoval.nim" line: 38 - errormsg: "type mismatch: got (type int) but expected 'int'" + errormsg: "type mismatch: got but expected 'int'" """ # A min-heap. -- cgit 1.4.1-2-gfad0