summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2024-04-16 18:46:59 +0800
committerGitHub <noreply@github.com>2024-04-16 12:46:59 +0200
commit20698b8057b09ace67ff0bc932aa552157ee7c9d (patch)
tree57c36d88689c8a60751a2ceae288fd705aa3d3a7
parent549ef24f35213302ba66e9e786c18ab9146940ee (diff)
downloadNim-20698b8057b09ace67ff0bc932aa552157ee7c9d.tar.gz
fixes #23494; Wrong type in object construction error message (#23504)
fixes #23494
-rw-r--r--compiler/astmsgs.nim6
-rw-r--r--compiler/semobjconstr.nim2
2 files changed, 7 insertions, 1 deletions
diff --git a/compiler/astmsgs.nim b/compiler/astmsgs.nim
index c990b36e8..aeeff1fd0 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 e29d723d7..96b2d702d 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"