Skip to content

Commit

Permalink
fix #19882 Improve error message when instantiating generics that lac… (
Browse files Browse the repository at this point in the history
#20356)

* fix #19882 Improve error message when instantiating generics that lack a type

* Update tests/errmsgs/t19882.nim

Co-authored-by: Clay Sweetser <[email protected]>
  • Loading branch information
bung87 and Varriount authored Sep 19, 2022
1 parent c4ba4f0 commit a302b26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/seminst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests/errmsgs/t19882.nim
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a302b26

Please sign in to comment.