summary refs log tree commit diff stats
path: root/compiler/semobjconstr.nim
diff options
context:
space:
mode:
authorBung <crc32@qq.com>2022-09-22 09:11:39 +0800
committerGitHub <noreply@github.com>2022-09-21 21:11:39 -0400
commit2afce84616e1de176c9e76a3e0146fff7ab1de10 (patch)
tree88b23bb12ca6603a7e7679b487983f0ec5a9b536 /compiler/semobjconstr.nim
parentde089d7fdb48a25069c3716ba00774b60c3da370 (diff)
downloadNim-2afce84616e1de176c9e76a3e0146fff7ab1de10.tar.gz
Improve error message when instantiating generics with object constructor (#20358)
* Improve error message when instantiating generics with object constructor

* follow suggestion

* Update compiler/semobjconstr.nim

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>

* Update tests/errmsgs/t19882_2.nim

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
Diffstat (limited to 'compiler/semobjconstr.nim')
-rw-r--r--compiler/semobjconstr.nim8
1 files changed, 6 insertions, 2 deletions
diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim
index f3efc1719..77bd6b975 100644
--- a/compiler/semobjconstr.nim
+++ b/compiler/semobjconstr.nim
@@ -398,8 +398,12 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
       # multiple times as long as they don't have closures.
       result.typ.flags.incl tfHasOwned
   if t.kind != tyObject:
-    return localErrorNode(c, result,
-      "object constructor needs an object type".dup(addDeclaredLoc(c.config, t)))
+    return localErrorNode(c, result, if t.kind != tyGenericBody:
+      "object constructor needs an object type".dup(addDeclaredLoc(c.config, t))
+      else: "cannot instantiate: '" &
+        typeToString(t, preferDesc) &
+        "'; the object's generic parameters cannot be inferred and must be explicitly given"
+      )
 
   # Check if the object is fully initialized by recursively testing each
   # field (if this is a case object, initialized fields in two different
.causal.agency/cgit-pink/about/'>cgit-pink 1.4.1-2-gfad0 (git 2.36.2.497.gbbea4dcf42) at 2025-01-26 09:58:01 +0000