From 9171a0c9d6f915974a890a523692c46e2dab0e1e Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:41:57 +0000 Subject: [PATCH] fixes #23494; Wrong type in object construction error message --- compiler/astmsgs.nim | 6 ++++++ compiler/semobjconstr.nim | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/astmsgs.nim b/compiler/astmsgs.nim index c990b36e88de..aeeff1fd0f15 100644 --- a/compiler/astmsgs.nim +++ b/compiler/astmsgs.nim @@ -24,6 +24,12 @@ proc addDeclaredLoc*(result: var string, conf: ConfigRef; typ: PType) = result.add " declared in " & toFileLineCol(conf, typ.sym.info) result.add "]" +proc addTypeNodeDeclaredLoc*(result: var string, conf: ConfigRef; typ: PType) = + result.add " [$1" % typ.kind.toHumanStr + if typ.sym != nil: + result.add " declared in " & toFileLineCol(conf, typ.sym.info) + result.add "]" + proc addDeclaredLocMaybe*(result: var string, conf: ConfigRef; typ: PType) = if optDeclaredLocs in conf.globalOptions: addDeclaredLoc(result, conf, typ) diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim index e29d723d7e86..96b2d702dabc 100644 --- a/compiler/semobjconstr.nim +++ b/compiler/semobjconstr.nim @@ -478,7 +478,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType result.typ.flags.incl tfHasOwned if t.kind != tyObject: return localErrorNode(c, result, if t.kind != tyGenericBody: - "object constructor needs an object type".dup(addDeclaredLoc(c.config, t)) + "object constructor needs an object type".dup(addTypeNodeDeclaredLoc(c.config, t)) else: "cannot instantiate: '" & typeToString(t, preferDesc) & "'; the object's generic parameters cannot be inferred and must be explicitly given"