Skip to content

Commit

Permalink
include generic bodies in allowMetaTypes (#23968)
Browse files Browse the repository at this point in the history
fixes #19848

Not sure why this wasn't the case already. The `if cl.allowMetaTypes:
return` line below for `tyFromExpr` [was added 10 years
ago](d5798b4).
Hopefully it was just negligence?
  • Loading branch information
metagn authored Aug 20, 2024
1 parent 6336d26 commit 1befb8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
result.kind = tyUserTypeClassInst

of tyGenericBody:
if cl.allowMetaTypes: return
localError(
cl.c.config,
cl.info,
Expand Down Expand Up @@ -645,7 +646,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =

for i, resulti in result.ikids:
if resulti != nil:
if resulti.kind == tyGenericBody:
if resulti.kind == tyGenericBody and not cl.allowMetaTypes:
localError(cl.c.config, if t.sym != nil: t.sym.info else: cl.info,
"cannot instantiate '" &
typeToString(result[i], preferDesc) &
Expand Down
16 changes: 16 additions & 0 deletions tests/generics/t19848.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
discard """
output: '''
todo
'''
"""

type
Maybe[T] = object
List[T] = object

proc dump[M: Maybe](a: List[M]) =
echo "todo"

var a: List[Maybe[int]]

dump(a)

0 comments on commit 1befb8d

Please sign in to comment.