summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBung <crc32@qq.com>2022-09-20 06:31:40 +0800
committerGitHub <noreply@github.com>2022-09-19 18:31:40 -0400
commita302b26e0eaa7a2074d3caac72f7c8a7e79993c5 (patch)
tree5e706d564166045885aebc7c9806b7f567d84be9
parentc4ba4f06f819d6356fff8ee8ee1df0392091de9a (diff)
downloadNim-a302b26e0eaa7a2074d3caac72f7c8a7e79993c5.tar.gz
fix #19882 Improve error message when instantiating generics that lac… (#20356)
* fix #19882 Improve error message when instantiating generics that lack a type

* Update tests/errmsgs/t19882.nim

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
-rw-r--r--compiler/seminst.nim3
-rw-r--r--tests/errmsgs/t19882.nim10
2 files changed, 12 insertions, 1 deletions
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index f5810c814..bd5eb1ec3 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -54,7 +54,8 @@ iterator instantiateGenericParamList(c: PContext, n: PNode, pt: TIdTable): PSym
           # later by semAsgn in return type inference scenario
           t = q.typ
         else:
-          localError(c.config, a.info, errCannotInstantiateX % s.name.s)
+          if q.typ.kind != tyCompositeTypeClass:
+            localError(c.config, a.info, errCannotInstantiateX % s.name.s)
           t = errorType(c)
       elif t.kind in {tyGenericParam, tyConcept}:
         localError(c.config, a.info, errCannotInstantiateX % q.name.s)
diff --git a/tests/errmsgs/t19882.nim b/tests/errmsgs/t19882.nim
new file mode 100644
index 000000000..1f2f95ab7
--- /dev/null
+++ b/tests/errmsgs/t19882.nim
@@ -0,0 +1,10 @@
+
+discard """
+  errormsg: "cannot instantiate 'A[T, P]' inside of type definition: 'init'; Maybe generic arguments are missing?"
+"""
+type A[T,P] = object
+  b:T
+  c:P
+proc init(): ref A =      
+  new(result)
+var a = init()