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>
This commit is contained in:
Bung 2022-09-20 06:31:40 +08:00 • committed by GitHub
commit a302b26e0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -54,6 +54,7 @@ iterator instantiateGenericParamList(c: PContext, n: PNode, pt: TIdTable): PSym
# later by semAsgn in return type inference scenario # later by semAsgn in return type inference scenario
t = q.typ t = q.typ
else: else:
if q.typ.kind != tyCompositeTypeClass:
localError(c.config, a.info, errCannotInstantiateX % s.name.s) localError(c.config, a.info, errCannotInstantiateX % s.name.s)
t = errorType(c) t = errorType(c)
elif t.kind in {tyGenericParam, tyConcept}: elif t.kind in {tyGenericParam, tyConcept}:

10
tests/errmsgs/t19882.nim Normal file
View file

@ -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()