mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 03:32:32 +00:00
include generic bodies in allowMetaTypes (#23968)
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](d5798b43de). Hopefully it was just negligence? (cherry picked from commit1befb8d4a3)
This commit is contained in:
@@ -578,6 +578,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||
result.kind = tyUserTypeClassInst
|
||||
|
||||
of tyGenericBody:
|
||||
if cl.allowMetaTypes: return
|
||||
localError(
|
||||
cl.c.config,
|
||||
cl.info,
|
||||
@@ -651,7 +652,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||
|
||||
for i in 0..<result.len:
|
||||
if result[i] != nil:
|
||||
if result[i].kind == tyGenericBody:
|
||||
if result[i].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) &
|
||||
|
||||
16
tests/generics/t19848.nim
Normal file
16
tests/generics/t19848.nim
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user