From 086efac49b746214c8d39347fa2d96f0f85413b2 Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Tue, 14 Jul 2020 15:22:48 +0800 Subject: [PATCH] fix #6608 (#14963) * fix #6608 --- compiler/semexprs.nim | 11 ++++++++++- tests/errmsgs/t6608.nim | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/t6608.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index de9f2198a2..fd9203f342 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -955,8 +955,17 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode = hasErrorType = true break if not hasErrorType: + let typ = n[0].typ msg.add(">\nbut expected one of: \n" & - typeToString(n[0].typ)) + typeToString(typ)) + # prefer notin preferToResolveSymbols + # t.sym != nil + # sfAnon notin t.sym.flags + # t.kind != tySequence(It is tyProc) + if typ.sym != nil and sfAnon notin typ.sym.flags and + typ.kind == tyProc: + msg.add(" = " & + typeToString(typ, preferDesc)) localError(c.config, n.info, msg) return errorNode(c, n) result = nil diff --git a/tests/errmsgs/t6608.nim b/tests/errmsgs/t6608.nim new file mode 100644 index 0000000000..3d82f3cd89 --- /dev/null +++ b/tests/errmsgs/t6608.nim @@ -0,0 +1,16 @@ +discard """ + cmd: "nim c --hints:off $file" + errormsg: "type mismatch: got <>" + nimout: '''t6608.nim(14, 4) Error: type mismatch: got <> +but expected one of: +AcceptCB = proc (s: string){.closure.}''' + line: 14 +""" + +type + AcceptCB = proc (s: string) + +proc x(x: AcceptCB) = + x() + +x()