mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-25 16:53:59 +00:00
* Fix for issue #10342. better message for generic subclass instantiation errors.
This commit is contained in:
@@ -490,7 +490,12 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||
result.kind = tyUserTypeClassInst
|
||||
|
||||
of tyGenericBody:
|
||||
localError(cl.c.config, cl.info, "cannot instantiate: '" & typeToString(t) & "'")
|
||||
localError(
|
||||
cl.c.config,
|
||||
cl.info,
|
||||
"cannot instantiate: '" &
|
||||
typeToString(t, preferDesc) &
|
||||
"'; Maybe generic arguments are missing?")
|
||||
result = errorType(cl.c)
|
||||
#result = replaceTypeVarsT(cl, lastSon(t))
|
||||
|
||||
@@ -555,6 +560,14 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||
|
||||
for i in countup(0, sonsLen(result) - 1):
|
||||
if result.sons[i] != nil:
|
||||
if result.sons[i].kind == tyGenericBody:
|
||||
localError(
|
||||
cl.c.config,
|
||||
t.sym.info,
|
||||
"cannot instantiate '" &
|
||||
typeToString(result.sons[i], preferDesc) &
|
||||
"' inside of type definition: '" &
|
||||
t.owner.name.s & "'; Maybe generic arguments are missing?")
|
||||
var r = replaceTypeVarsT(cl, result.sons[i])
|
||||
if result.kind == tyObject:
|
||||
# carefully coded to not skip the precious tyGenericInst:
|
||||
|
||||
@@ -456,12 +456,18 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||
result = $t.n.intVal
|
||||
else:
|
||||
result = "int literal(" & $t.n.intVal & ")"
|
||||
of tyGenericBody, tyGenericInst, tyGenericInvocation:
|
||||
of tyGenericInst, tyGenericInvocation:
|
||||
result = typeToString(t.sons[0]) & '['
|
||||
for i in countup(1, sonsLen(t)-1-ord(t.kind != tyGenericInvocation)):
|
||||
if i > 1: add(result, ", ")
|
||||
add(result, typeToString(t.sons[i], preferGenericArg))
|
||||
add(result, ']')
|
||||
of tyGenericBody:
|
||||
result = typeToString(t.lastSon) & '['
|
||||
for i in countup(0, sonsLen(t)-2):
|
||||
if i > 0: add(result, ", ")
|
||||
add(result, typeToString(t.sons[i], preferTypeName))
|
||||
add(result, ']')
|
||||
of tyTypeDesc:
|
||||
if t.sons[0].kind == tyNone: result = "typedesc"
|
||||
else: result = "type " & typeToString(t.sons[0])
|
||||
@@ -612,7 +618,6 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||
result = typeToStr[t.kind]
|
||||
result.addTypeFlags(t)
|
||||
|
||||
|
||||
proc firstOrd*(conf: ConfigRef; t: PType): BiggestInt =
|
||||
case t.kind
|
||||
of tyBool, tyChar, tySequence, tyOpenArray, tyString, tyVarargs, tyProxy:
|
||||
|
||||
11
tests/generics/tsubclassgenericerror.nim
Normal file
11
tests/generics/tsubclassgenericerror.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
discard """
|
||||
errormsg: "cannot instantiate 'GenericParentType[T]' inside of type definition: 'GenericChildType'; Maybe generic arguments are missing?"
|
||||
line: 8
|
||||
"""
|
||||
|
||||
type
|
||||
GenericParentType[T] = ref object of RootObj
|
||||
GenericChildType[T] = ref object of GenericParentType # missing the [T]
|
||||
val: T
|
||||
|
||||
var instance : GenericChildType[int] = nil
|
||||
@@ -1,5 +1,5 @@
|
||||
discard """
|
||||
errormsg: "cannot instantiate: 'GenericNodeObj'"
|
||||
errormsg: "cannot instantiate: 'GenericNodeObj[T]'; Maybe generic arguments are missing?"
|
||||
line: 21
|
||||
"""
|
||||
# bug #2509
|
||||
|
||||
Reference in New Issue
Block a user