diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 242b0658727d..6c117fd36160 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -8,7 +8,7 @@ # import - std/[strutils, os, tables, terminal, macros, times], + std/[strutils, os, tables, terminal, macros, times, colors, strformat, parseutils], std/private/miscdollars, options, ropes, lineinfos, pathutils, strutils2 @@ -477,12 +477,68 @@ proc sourceLine*(conf: ConfigRef; i: TLineInfo): string = result = conf.m.fileInfos[i.fileIndex.int32].lines[i.line.int-1] -proc getSurroundingSrc(conf: ConfigRef; info: TLineInfo): string = +proc colorError(s: string, color: ForegroundColor, conf: ConfigRef): string = + if optUseColors in conf.globalOptions: + template isQuote(val: untyped): untyped = val == '\'' + template isNotQuote(val: untyped): untyped = val != '\'' + let parsable = (s.count('"').mod 2) == 0 + var + pos = 0 + while pos < s.len: + if s[pos].isQuote: + if pos < s.high and s[pos + 1].isQuote: + result.add s[pos..(pos + 1)] + var inDoubleQuote = false + inc pos + let start = pos + while (pos < s.len and s[pos].isNotQuote) or inDoubleQuote: + if s[pos] == '"' and parsable: + inDoubleQuote = not inDoubleQuote + inc pos + #Highlight error + if pos < s.len and parsable: + if (s[pos].isQuote): + result.add fmt"""{color.ansiForegroundColorCode}{s[start..(pos - 1)]}{ansiResetCode}""" + else: + result.add s[start..(pos - 1)] + else: + result.add s[start..s.high] + break + else: + result.add s[pos] + inc pos + else: + result = s + +proc getSurroundingSrc(result: var string, conf: ConfigRef; info: TLineInfo, color: ForegroundColor) = if conf.hasHint(hintSource) and info != unknownLineInfo: const indent = " " - result = "\n" & indent & $sourceLine(conf, info) - if info.col >= 0: - result.add "\n" & indent & spaces(info.col) & '^' + if optUseColors in conf.globalOptions: + var msg = $sourceLine(conf, info) + let + colorEnd = + case msg[info.col]: + of IdentStartChars: + info.col + 1 + msg.skipUntil({'\0'..'\255'} - IdentChars, info.col) + of '[': # + 2 due to wanting to include the sym in the coloring + info.col + 2 + msg.skipUntil(']', info.col) + of '(': # + 2 due to wanting to include the sym in the coloring + info.col + 2 + msg.skipUntil(')', info.col) + of '.': # + 2 due to wanting to include the sym in the coloring + info.col + 2 + msg.skipUntil({'.', ' ', '(', '['}, info.col) + else: msg.high + + msg.insert("'", info.col) + msg.insert("'", colorEnd) + msg.insert("\n ", 0) + + if info.col >= 0: + msg.add "\n" & indent & spaces(info.col) & "'^'" + result.add msg.colorError(color, conf) + else: + result.add "\n" & indent & $sourceLine(conf, info) + if info.col >= 0: + result.add "\n" & indent & spaces(info.col) & '^' proc formatMsg*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string): string = let title = case msg @@ -539,7 +595,8 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string, color = HintColor inc(conf.hintCounter) - let s = if isRaw: arg else: getMessageStr(msg, arg) + let strMsg = if isRaw: arg else: getMessageStr(msg, arg) + var s = colorError(strMsg, color, conf) if not ignoreMsg: let loc = if info != unknownLineInfo: conf.toFileLineCol(info) & " " else: "" # we could also show `conf.cmdInput` here for `projectIsCmd` @@ -550,8 +607,9 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string, if msg == hintProcessing and conf.hintProcessingDots: msgWrite(conf, ".") else: + getSurroundingSrc(s, conf, info, color) styledMsgWriteln(styleBright, loc, resetStyle, color, title, resetStyle, s, KindColor, kindmsg, - resetStyle, conf.getSurroundingSrc(info), conf.unitSep) + resetStyle, conf.unitSep) if hintMsgOrigin in conf.mainPackageNotes: # xxx needs a bit of refactoring to honor `conf.filenameOption` styledMsgWriteln(styleBright, toFileLineCol(info2), resetStyle, diff --git a/compiler/semcall.nim b/compiler/semcall.nim index d8dba3e6c148..216b8cc31398 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -11,7 +11,7 @@ # included from sem.nim from algorithm import sort - +from renderer import quoteExpr proc sameMethodDispatcher(a, b: PSym): bool = result = false if a.kind == skMethod and b.kind == skMethod: @@ -274,8 +274,8 @@ const errTypeMismatch = "type mismatch: got <" errButExpected = "but expected one of:" errUndeclaredField = "undeclared field: '$1'" - errUndeclaredRoutine = "attempting to call undeclared routine: '$1'" - errBadRoutine = "attempting to call routine: '$1'$2" + errUndeclaredRoutine = "attempting to call undeclared routine: $1" + errBadRoutine = "attempting to call routine: $1$2" errAmbiguousCallXYZ = "ambiguous call; both $1 and $2 match for: $3" proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) = @@ -287,7 +287,7 @@ proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) = globalError(c.config, n.info, "type mismatch") return if errors.len == 0: - localError(c.config, n.info, "expression '$1' cannot be called" % n[0].renderTree) + localError(c.config, n.info, "expression $1 cannot be called" % n[0].renderTree.quoteExpr) return let (prefer, candidates) = presentFailedCandidates(c, n, errors) @@ -344,8 +344,8 @@ proc getMsgDiagnostic(c: PContext, flags: TExprFlags, n, f: PNode): string = let suffix = if result.len > 0: " " & result else: "" result = errUndeclaredField % ident & typeHint & suffix else: - if result.len == 0: result = errUndeclaredRoutine % ident - else: result = errBadRoutine % [ident, result] + if result.len == 0: result = errUndeclaredRoutine % ident.quoteExpr + else: result = errBadRoutine % [ident.quoteExpr, result] proc resolveOverloads(c: PContext, n, orig: PNode, filter: TSymKinds, flags: TExprFlags, @@ -432,8 +432,8 @@ proc resolveOverloads(c: PContext, n, orig: PNode, return elif result.state != csMatch: if nfExprCall in n.flags: - localError(c.config, n.info, "expression '$1' cannot be called" % - renderTree(n, {renderNoComments})) + localError(c.config, n.info, "expression $1 cannot be called" % + renderTree(n, {renderNoComments}).quoteExpr) else: if {nfDotField, nfDotSetter} * n.flags != {}: # clean up the inserted ops @@ -457,8 +457,8 @@ proc resolveOverloads(c: PContext, n, orig: PNode, args.add(")") localError(c.config, n.info, errAmbiguousCallXYZ % [ - getProcHeader(c.config, result.calleeSym), - getProcHeader(c.config, alt.calleeSym), + getProcHeader(c.config, result.calleeSym).quoteExpr, + getProcHeader(c.config, alt.calleeSym).quoteExpr, args]) proc instGenericConvertersArg*(c: PContext, a: PNode, x: TCandidate) = @@ -664,8 +664,8 @@ proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode = # number of generic type parameters: if s.ast[genericParamsPos].safeLen != n.len-1: let expected = s.ast[genericParamsPos].safeLen - localError(c.config, getCallLineInfo(n), errGenerated, "cannot instantiate: '" & renderTree(n) & - "'; got " & $(n.len-1) & " typeof(s) but expected " & $expected) + localError(c.config, getCallLineInfo(n), errGenerated, "cannot instantiate: " & renderTree(n) & + "; got " & $(n.len-1) & " typeof(s) but expected " & $expected) return n result = explicitGenericSym(c, n, s) if result == nil: result = explicitGenericInstError(c, n) diff --git a/compiler/types.nim b/compiler/types.nim index 49ebb1daea7a..860f564fbd6d 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -53,10 +53,10 @@ proc typeToString*(typ: PType; prefer: TPreferedDesc = preferName): string proc addTypeDeclVerboseMaybe*(result: var string, conf: ConfigRef; typ: PType) = if optDeclaredLocs in conf.globalOptions: - result.add typeToString(typ, preferMixed) + result.add typeToString(typ, preferMixed).quoteExpr result.addDeclaredLoc(conf, typ) else: - result.add typeToString(typ) + result.add typeToString(typ).quoteExpr template `$`*(typ: PType): string = typeToString(typ) diff --git a/tests/concepts/t3330.nim b/tests/concepts/t3330.nim index b92af5485395..2f7c530b7b70 100644 --- a/tests/concepts/t3330.nim +++ b/tests/concepts/t3330.nim @@ -5,29 +5,29 @@ t3330.nim(70, 4) Error: type mismatch: got but expected one of: proc test(foo: Foo[int]) first type mismatch at position: 1 - required type for foo: Foo[int] - but expression 'bar' is of type: Bar[system.int] + required type for foo: 'Foo[int]' + but expression 'bar' is of type: 'Bar[system.int]' t3330.nim(55, 8) Hint: Non-matching candidates for add(k, string, T) proc add(x: var string; y: char) first type mismatch at position: 1 - required type for x: var string - but expression 'k' is of type: Alias + required type for x: 'var string' + but expression 'k' is of type: 'Alias' proc add(x: var string; y: cstring) first type mismatch at position: 1 - required type for x: var string - but expression 'k' is of type: Alias + required type for x: 'var string' + but expression 'k' is of type: 'Alias' proc add(x: var string; y: string) first type mismatch at position: 1 - required type for x: var string - but expression 'k' is of type: Alias + required type for x: '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 for x: var seq[T] - but expression 'k' is of type: Alias + required type for x: 'var seq[T]' + but expression 'k' is of type: 'Alias' proc add[T](x: var seq[T]; y: sink T) first type mismatch at position: 1 - required type for x: var seq[T] - but expression 'k' is of type: Alias + required type for x: 'var seq[T]' + but expression 'k' is of type: 'Alias' t3330.nim(55, 8) template/generic instantiation of `add` from here t3330.nim(62, 6) Foo: 'bar.value' cannot be assigned to diff --git a/tests/concepts/texplain.nim b/tests/concepts/texplain.nim index 49eb8eb6b1e6..99cf40d13d1e 100644 --- a/tests/concepts/texplain.nim +++ b/tests/concepts/texplain.nim @@ -4,14 +4,14 @@ discard """ texplain.nim(162, 10) Hint: Non-matching candidates for e(y) proc e(i: int): int first type mismatch at position: 1 - required type for i: int - but expression 'y' is of type: MatchingType + required type for i: 'int' + but expression 'y' is of type: 'MatchingType' texplain.nim(165, 7) Hint: Non-matching candidates for e(10) proc e(o: ExplainedConcept): int first type mismatch at position: 1 - required type for o: ExplainedConcept - but expression '10' is of type: int literal(10) + required type for o: 'ExplainedConcept' + but expression '10' is of type: 'int literal(10)' texplain.nim(128, 6) ExplainedConcept: undeclared field: 'foo' texplain.nim(128, 6) ExplainedConcept: undeclared field: '.' texplain.nim(128, 6) ExplainedConcept: expression '.' cannot be called @@ -26,8 +26,8 @@ texplain.nim(128, 5) ExplainedConcept: concept predicate failed texplain.nim(168, 10) Hint: Non-matching candidates for e(10) proc e(o: ExplainedConcept): int first type mismatch at position: 1 - required type for o: ExplainedConcept - but expression '10' is of type: int literal(10) + required type for o: 'ExplainedConcept' + but expression '10' is of type: 'int literal(10)' texplain.nim(128, 6) ExplainedConcept: undeclared field: 'foo' texplain.nim(128, 6) ExplainedConcept: undeclared field: '.' texplain.nim(128, 6) ExplainedConcept: expression '.' cannot be called @@ -43,12 +43,12 @@ texplain.nim(172, 20) Error: type mismatch: got but expected one of: proc e(i: int): int first type mismatch at position: 1 - required type for i: int - but expression 'n' is of type: NonMatchingType + required type for i: 'int' + but expression 'n' is of type: 'NonMatchingType' proc e(o: ExplainedConcept): int first type mismatch at position: 1 - required type for o: ExplainedConcept - but expression 'n' is of type: NonMatchingType + required type for o: 'ExplainedConcept' + but expression 'n' is of type: 'NonMatchingType' texplain.nim(172, 9) template/generic instantiation of `assert` from here texplain.nim(128, 5) ExplainedConcept: concept predicate failed @@ -57,36 +57,36 @@ texplain.nim(173, 20) Error: type mismatch: got but expected one of: proc r(i: string): int first type mismatch at position: 1 - required type for i: string - but expression 'n' is of type: NonMatchingType + required type for i: 'string' + but expression 'n' is of type: 'NonMatchingType' proc r(o: RegularConcept): int first type mismatch at position: 1 - required type for o: RegularConcept - but expression 'n' is of type: NonMatchingType + required type for o: 'RegularConcept' + but expression 'n' is of type: 'NonMatchingType' texplain.nim(173, 9) template/generic instantiation of `assert` from here texplain.nim(132, 5) RegularConcept: concept predicate failed proc r[T](a: SomeNumber; b: T; c: auto) first type mismatch at position: 1 - required type for a: SomeNumber - but expression 'n' is of type: NonMatchingType + required type for a: 'SomeNumber' + but expression 'n' is of type: 'NonMatchingType' expression: r(n) texplain.nim(174, 20) Hint: Non-matching candidates for r(y) proc r(i: string): int first type mismatch at position: 1 - required type for i: string - but expression 'y' is of type: MatchingType + required type for i: 'string' + but expression 'y' is of type: 'MatchingType' proc r[T](a: SomeNumber; b: T; c: auto) first type mismatch at position: 1 - required type for a: SomeNumber - but expression 'y' is of type: MatchingType + required type for a: 'SomeNumber' + but expression 'y' is of type: 'MatchingType' texplain.nim(182, 2) Error: type mismatch: got but expected one of: proc f(o: NestedConcept) first type mismatch at position: 1 - required type for o: NestedConcept - but expression 'y' is of type: MatchingType + required type for o: 'NestedConcept' + but expression 'y' is of type: 'MatchingType' texplain.nim(132, 6) RegularConcept: undeclared field: 'foo' texplain.nim(132, 6) RegularConcept: undeclared field: '.' texplain.nim(132, 6) RegularConcept: expression '.' cannot be called diff --git a/tests/errmsgs/t8434.nim b/tests/errmsgs/t8434.nim index 5d962ee5c908..a78f58b3fbb1 100644 --- a/tests/errmsgs/t8434.nim +++ b/tests/errmsgs/t8434.nim @@ -3,8 +3,8 @@ discard """ 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 + 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) ''' diff --git a/tests/errmsgs/tdeclaredlocs.nim b/tests/errmsgs/tdeclaredlocs.nim index 926ebf2178c4..f9a0c616f15d 100644 --- a/tests/errmsgs/tdeclaredlocs.nim +++ b/tests/errmsgs/tdeclaredlocs.nim @@ -7,44 +7,44 @@ tdeclaredlocs.nim(92, 3) Error: type mismatch: got 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)] + 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)] + 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)] + 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)] + 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)] + 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)] + 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)] + 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)] + 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)] + 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)] + 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) ''' diff --git a/tests/errmsgs/tdetailed_position.nim b/tests/errmsgs/tdetailed_position.nim index ecece797295b..9275f2bad148 100644 --- a/tests/errmsgs/tdetailed_position.nim +++ b/tests/errmsgs/tdetailed_position.nim @@ -1,13 +1,14 @@ discard """ -cmd: "nim check $file" +cmd: "nim check --hints: off $file" errormsg: "type mismatch: got " nimout: ''' +tdetailed_position.nim(23, 5) Error: type mismatch: got but expected one of: proc main(a, b, c: string) first type mismatch at position: 1 - required type for a: string - but expression '1' is of type: int literal(1) + required type for a: 'string' + but expression '1' is of type: 'int literal(1)' expression: main(1, 2, 3) ''' diff --git a/tests/errmsgs/tgcsafety.nim b/tests/errmsgs/tgcsafety.nim index 6021d19e1a7a..95e7584af87f 100644 --- a/tests/errmsgs/tgcsafety.nim +++ b/tests/errmsgs/tgcsafety.nim @@ -1,16 +1,17 @@ discard """ -cmd: "nim check $file" +cmd: "nim check --hints:off $file" errormsg: "type mismatch: got .}>" nimout: ''' -tgcsafety.nim(31, 18) Error: type mismatch: got .}> +tgcsafety.nim(32, 18) Error: type mismatch: got .}> but expected one of: proc serve(server: AsyncHttpServer; port: Port; callback: proc (request: Request): Future[void] {.closure, gcsafe.}; address = ""; assumedDescriptorsPerRequest = -1): 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: .} + 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: .}' + Pragma mismatch: got '{..}', but expected '{.gcsafe.}'. 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/tproc_mismatch.nim b/tests/errmsgs/tproc_mismatch.nim index 4ddc7635ec55..72eff4c08966 100644 --- a/tests/errmsgs/tproc_mismatch.nim +++ b/tests/errmsgs/tproc_mismatch.nim @@ -9,8 +9,8 @@ tproc_mismatch.nim(39, 6) Error: type mismatch: got +tsigmatch.nim(113, 4) Error: type mismatch: got 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 + 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, locks: 0.})> +tsigmatch.nim(127, 6) Error: type mismatch: got <(string, proc (){.gcsafe, locks: 0.})> 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.}) + required type for x: '(string, proc (){.closure.})' + but expression '("foobar", proc () = echo(["Hello!"]))' is of type: '(string, proc (){.gcsafe, locks: 0.})' expression: foo(("foobar", proc () = echo(["Hello!"]))) -tsigmatch.nim(132, 11) Error: type mismatch: got +tsigmatch.nim(134, 11) Error: type mismatch: got 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.} + required type for op: 'proc (x: T): S{.cdecl.}' + but expression 'fun' is of type: 'proc (s: string): string{.noSideEffect, gcsafe, locks: 0.}' + Calling convention mismatch: got '{.nimcall.}', but expected '{.cdecl.}'. 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.} + required type for op: 'proc (x: T): S{.safecall.}' + but expression 'fun' is of type: 'proc (s: string): string{.noSideEffect, gcsafe, locks: 0.}' + Calling convention mismatch: got '{.nimcall.}', but expected '{.safecall.}'. expression: foo(fun) -tsigmatch.nim(143, 13) Error: type mismatch: got +tsigmatch.nim(145, 13) Error: type mismatch: got but expected one of: proc takesFuncs(fs: openArray[proc (x: int) {.gcsafe, locks: 0.}]) 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, locks: 0.}]' + but expression '[proc (x: int) {.gcsafe, locks: 0.} = echo [x]]' is of type: 'array[0..0, proc (x: int){.gcsafe, locks: 0.}]' expression: takesFuncs([proc (x: int) {.gcsafe, locks: 0.} = echo [x]]) -tsigmatch.nim(149, 4) Error: type mismatch: got +tsigmatch.nim(151, 4) Error: type mismatch: got 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 +tsigmatch.nim(158, 4) Error: type mismatch: got 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 + 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 + 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 +tsigmatch.nim(166, 4) Error: type mismatch: got 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) + 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 + 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 +tsigmatch.nim(173, 7) Error: type mismatch: got 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 + 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 + required type for a1: 'float' + but expression 'default(Mystring)' is of type: 'Mystring' expression: fun1(default(Mystring), "asdf") ''' diff --git a/tests/errmsgs/tsigmatch2.nim b/tests/errmsgs/tsigmatch2.nim index 4996634c93e8..e6ca8dc0194c 100644 --- a/tests/errmsgs/tsigmatch2.nim +++ b/tests/errmsgs/tsigmatch2.nim @@ -5,12 +5,12 @@ tsigmatch2.nim(40, 14) Error: type mismatch: got 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 + 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 + 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) @@ -18,8 +18,8 @@ tsigmatch2.nim(46, 7) Error: type mismatch: got 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) + required type for args: 'varargs[string]' + but expression '1' is of type: 'int literal(1)' expression: foo 1 ''' diff --git a/tests/errmsgs/tundeclared_routine.nim b/tests/errmsgs/tundeclared_routine.nim index 2f1320fff51a..3ae79c7cf2d9 100644 --- a/tests/errmsgs/tundeclared_routine.nim +++ b/tests/errmsgs/tundeclared_routine.nim @@ -2,14 +2,35 @@ 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, 15) Error: attempting to call routine: 'bad5' +tundeclared_routine.nim(45, 17) Error: attempting to call routine: 'myiter' + found tundeclared_routine.myiter(a: string) [iterator declared in tundeclared_routine.nim(43, 12)] + found tundeclared_routine.myiter() [iterator declared in tundeclared_routine.nim(44, 12)] +tundeclared_routine.nim(45, 17) Error: attempting to call routine: 'myiter' + found tundeclared_routine.myiter(a: string) [iterator declared in tundeclared_routine.nim(43, 12)] + found tundeclared_routine.myiter() [iterator declared in tundeclared_routine.nim(44, 12)] +tundeclared_routine.nim(45, 17) Error: expression 'myiter' cannot be called +tundeclared_routine.nim(45, 17) Error: expression '' has no type (or is ambiguous) +tundeclared_routine.nim(45, 7) Error: 'let' symbol requires an initialization +tundeclared_routine.nim(50, 28) Error: invalid pragma: myPragma +tundeclared_routine.nim(57, 13) Error: undeclared field: 'bar3' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(54, 8)] + found tundeclared_routine.bar3() [iterator declared in tundeclared_routine.nim(56, 12)] +tundeclared_routine.nim(57, 13) Error: undeclared field: '.' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(54, 8)] +tundeclared_routine.nim(57, 13) Error: expression '.' cannot be called +tundeclared_routine.nim(57, 13) Error: expression '' has no type (or is ambiguous) +tundeclared_routine.nim(57, 7) Error: 'let' symbol requires an initialization +tundeclared_routine.nim(62, 13) Error: undeclared field: 'bar4' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(60, 8)] +tundeclared_routine.nim(62, 13) Error: undeclared field: '.' for type tundeclared_routine.Foo [type declared in tundeclared_routine.nim(60, 8)] +tundeclared_routine.nim(62, 13) Error: expression '.' cannot be called +tundeclared_routine.nim(62, 13) Error: expression '' has no type (or is ambiguous) +tundeclared_routine.nim(62, 7) Error: 'let' symbol requires an initialization +tundeclared_routine.nim(65, 11) Error: undeclared identifier: 'bad5' +tundeclared_routine.nim(65, 15) Error: attempting to call routine: 'bad5' + found 'bad5' [unknown declared in tundeclared_routine.nim(65, 11)] +tundeclared_routine.nim(65, 15) Error: attempting to call routine: 'bad5' + found 'bad5' [unknown declared in tundeclared_routine.nim(65, 11)] +tundeclared_routine.nim(65, 15) Error: expression 'bad5' cannot be called +tundeclared_routine.nim(65, 15) Error: expression '' has no type (or is ambiguous) +tundeclared_routine.nim(65, 7) Error: 'let' symbol requires an initialization ''' """ diff --git a/tests/errmsgs/tunknown_named_parameter.nim b/tests/errmsgs/tunknown_named_parameter.nim index d3dd6cd2d339..cce0d0af1e25 100644 --- a/tests/errmsgs/tunknown_named_parameter.nim +++ b/tests/errmsgs/tunknown_named_parameter.nim @@ -1,21 +1,24 @@ discard """ -cmd: "nim check $file" -errormsg: "type mismatch: got " +cmd: "nim check --hints:off $file" +action: reject nimout: ''' +tunknown_named_parameter.nim(30, 10) Error: type mismatch: got +but expected one of: 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] + 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] + 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) +tunknown_named_parameter.nim(29, 8) Warning: imported and not used: 'strutils' [UnusedImport] ''' """ diff --git a/tests/errmsgs/twrong_at_operator.nim b/tests/errmsgs/twrong_at_operator.nim index 438186f014d4..5a6ea559f5bb 100644 --- a/tests/errmsgs/twrong_at_operator.nim +++ b/tests/errmsgs/twrong_at_operator.nim @@ -1,18 +1,20 @@ discard """ -errormsg: "type mismatch: got " +cmd: '''nim check --hints:off $file''' +action: reject nimout: ''' -twrong_at_operator.nim(21, 30) Error: type mismatch: got +twrong_at_operator.nim(23, 30) Error: type mismatch: got 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]] + 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] first type mismatch at position: 1 - required type for a: openArray[T] - but expression '[int]' is of type: array[0..0, typedesc[int]] + required type for a: 'openArray[T]' + but expression '[int]' is of type: 'array[0..0, typedesc[int]]' expression: @[int] +twrong_at_operator.nim(23, 30) Error: expression '' has no type (or is ambiguous) ''' disabled: "32bit" """ diff --git a/tests/misc/t9039.nim b/tests/misc/t9039.nim index ba636d1db2c3..3462262c6c8a 100644 --- a/tests/misc/t9039.nim +++ b/tests/misc/t9039.nim @@ -1,8 +1,16 @@ discard """ action: reject nimout: ''' -t9039.nim(22, 22) Error: type mismatch: got -but expression 'nesting + 1' is of type: int +t9039.nim(30, 22) Error: type mismatch: got +but expected one of: +func shapeBad[T: not char](s: openArray[T]; rank: static[int]; nesting = 0; + parent_shape = default(array[rank, int])): array[ + rank, int] + first type mismatch at position: 2 + required type for rank: 'static[int]' + but expression 'nesting + 1' is of type: 'int' + +expression: shapeBad(s[0], nesting + 1, result) ''' """ diff --git a/tests/range/tenums.nim b/tests/range/tenums.nim index 3cdf06fe291e..cb8398658bad 100644 --- a/tests/range/tenums.nim +++ b/tests/range/tenums.nim @@ -6,16 +6,16 @@ tenums.nim(32, 20) Error: type mismatch: got but expected one of: proc takesChristmasColor(color: ChristmasColors) first type mismatch at position: 1 - required type for color: ChristmasColors - but expression 'A' is of type: Letters + required type for color: 'ChristmasColors' + but expression 'A' is of type: 'Letters' expression: takesChristmasColor(A) tenums.nim(33, 20) Error: type mismatch: got but expected one of: proc takesChristmasColor(color: ChristmasColors) first type mismatch at position: 1 - required type for color: ChristmasColors - but expression 'BC(C)' is of type: BC + required type for color: 'ChristmasColors' + but expression 'BC(C)' is of type: 'BC' expression: takesChristmasColor(BC(C)) ''' diff --git a/tests/typerel/t7600_1.nim b/tests/typerel/t7600_1.nim index e9d01bd0d8bb..3b0de3d10bee 100644 --- a/tests/typerel/t7600_1.nim +++ b/tests/typerel/t7600_1.nim @@ -4,8 +4,8 @@ nimout: '''t7600_1.nim(21, 6) Error: type mismatch: got but expected one of: proc test[T](x: Paper[T]) first type mismatch at position: 1 - required type for x: Paper[test.T] - but expression 'tn' is of type: Thin[system.int] + required type for x: 'Paper[test.T]' + but expression 'tn' is of type: 'Thin[system.int]' expression: test tn''' """ diff --git a/tests/typerel/t7600_2.nim b/tests/typerel/t7600_2.nim index 371707f4c509..c78672f1fd77 100644 --- a/tests/typerel/t7600_2.nim +++ b/tests/typerel/t7600_2.nim @@ -4,8 +4,8 @@ nimout: '''t7600_2.nim(20, 6) Error: type mismatch: got but expected one of: proc test(x: Paper) first type mismatch at position: 1 - required type for x: Paper - but expression 'tn' is of type: Thin + required type for x: 'Paper' + but expression 'tn' is of type: 'Thin' expression: test tn''' """ diff --git a/tests/varres/tprevent_forloopvar_mutations.nim b/tests/varres/tprevent_forloopvar_mutations.nim index 96bb208c2386..ec2265502904 100644 --- a/tests/varres/tprevent_forloopvar_mutations.nim +++ b/tests/varres/tprevent_forloopvar_mutations.nim @@ -4,7 +4,7 @@ discard """ but expected one of: proc inc[T: Ordinal](x: var T; y = 1) first type mismatch at position: 1 - required type for x: var T: Ordinal + required type for x: 'var T: Ordinal' but expression 'i' is immutable, not 'var' expression: inc i