* Fix for issue #10342. better message for generic subclass instantiation errors.
This commit is contained in:
parent
a0c07ef863
commit
94f6a6b294
4 changed files with 33 additions and 4 deletions
|
|
@ -490,7 +490,12 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||||
result.kind = tyUserTypeClassInst
|
result.kind = tyUserTypeClassInst
|
||||||
|
|
||||||
of tyGenericBody:
|
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 = errorType(cl.c)
|
||||||
#result = replaceTypeVarsT(cl, lastSon(t))
|
#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):
|
for i in countup(0, sonsLen(result) - 1):
|
||||||
if result.sons[i] != nil:
|
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])
|
var r = replaceTypeVarsT(cl, result.sons[i])
|
||||||
if result.kind == tyObject:
|
if result.kind == tyObject:
|
||||||
# carefully coded to not skip the precious tyGenericInst:
|
# carefully coded to not skip the precious tyGenericInst:
|
||||||
|
|
|
||||||
|
|
@ -456,12 +456,18 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||||
result = $t.n.intVal
|
result = $t.n.intVal
|
||||||
else:
|
else:
|
||||||
result = "int literal(" & $t.n.intVal & ")"
|
result = "int literal(" & $t.n.intVal & ")"
|
||||||
of tyGenericBody, tyGenericInst, tyGenericInvocation:
|
of tyGenericInst, tyGenericInvocation:
|
||||||
result = typeToString(t.sons[0]) & '['
|
result = typeToString(t.sons[0]) & '['
|
||||||
for i in countup(1, sonsLen(t)-1-ord(t.kind != tyGenericInvocation)):
|
for i in countup(1, sonsLen(t)-1-ord(t.kind != tyGenericInvocation)):
|
||||||
if i > 1: add(result, ", ")
|
if i > 1: add(result, ", ")
|
||||||
add(result, typeToString(t.sons[i], preferGenericArg))
|
add(result, typeToString(t.sons[i], preferGenericArg))
|
||||||
add(result, ']')
|
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:
|
of tyTypeDesc:
|
||||||
if t.sons[0].kind == tyNone: result = "typedesc"
|
if t.sons[0].kind == tyNone: result = "typedesc"
|
||||||
else: result = "type " & typeToString(t.sons[0])
|
else: result = "type " & typeToString(t.sons[0])
|
||||||
|
|
@ -612,7 +618,6 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||||
result = typeToStr[t.kind]
|
result = typeToStr[t.kind]
|
||||||
result.addTypeFlags(t)
|
result.addTypeFlags(t)
|
||||||
|
|
||||||
|
|
||||||
proc firstOrd*(conf: ConfigRef; t: PType): BiggestInt =
|
proc firstOrd*(conf: ConfigRef; t: PType): BiggestInt =
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyBool, tyChar, tySequence, tyOpenArray, tyString, tyVarargs, tyProxy:
|
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 """
|
discard """
|
||||||
errormsg: "cannot instantiate: 'GenericNodeObj'"
|
errormsg: "cannot instantiate: 'GenericNodeObj[T]'; Maybe generic arguments are missing?"
|
||||||
line: 21
|
line: 21
|
||||||
"""
|
"""
|
||||||
# bug #2509
|
# bug #2509
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue