From a302b26e0eaa7a2074d3caac72f7c8a7e79993c5 Mon Sep 17 00:00:00 2001 From: Bung Date: Tue, 20 Sep 2022 06:31:40 +0800 Subject: [PATCH] =?UTF-8?q?fix=20#19882=20Improve=20error=20message=20when?= =?UTF-8?q?=20instantiating=20generics=20that=20lac=E2=80=A6=20(#20356)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix #19882 Improve error message when instantiating generics that lack a type * Update tests/errmsgs/t19882.nim Co-authored-by: Clay Sweetser --- compiler/seminst.nim | 3 ++- tests/errmsgs/t19882.nim | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/t19882.nim diff --git a/compiler/seminst.nim b/compiler/seminst.nim index f5810c814336..bd5eb1ec319c 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 000000000000..1f2f95ab738c --- /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()