fixes #4084
This commit is contained in:
parent
c870e831c8
commit
e04f319540
4 changed files with 38 additions and 10 deletions
|
|
@ -65,15 +65,6 @@ template semIdeForTemplateOrGeneric(c: PContext; n: PNode;
|
||||||
# echo "passing to safeSemExpr: ", renderTree(n)
|
# echo "passing to safeSemExpr: ", renderTree(n)
|
||||||
discard safeSemExpr(c, n)
|
discard safeSemExpr(c, n)
|
||||||
|
|
||||||
proc typeMismatch(n: PNode, formal, actual: PType) =
|
|
||||||
if formal.kind != tyError and actual.kind != tyError:
|
|
||||||
let named = typeToString(formal)
|
|
||||||
let desc = typeToString(formal, preferDesc)
|
|
||||||
let x = if named == desc: named else: named & " = " & desc
|
|
||||||
localError(n.info, errGenerated, msgKindToString(errTypeMismatch) &
|
|
||||||
typeToString(actual) & ") " &
|
|
||||||
`%`(msgKindToString(errButExpectedX), [x]))
|
|
||||||
|
|
||||||
proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
|
proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
|
||||||
if arg.typ.isNil:
|
if arg.typ.isNil:
|
||||||
localError(arg.info, errExprXHasNoType,
|
localError(arg.info, errExprXHasNoType,
|
||||||
|
|
|
||||||
|
|
@ -361,7 +361,19 @@ proc explicitGenericInstError(n: PNode): PNode =
|
||||||
|
|
||||||
proc explicitGenericSym(c: PContext, n: PNode, s: PSym): PNode =
|
proc explicitGenericSym(c: PContext, n: PNode, s: PSym): PNode =
|
||||||
var m: TCandidate
|
var m: TCandidate
|
||||||
initCandidate(c, m, s, n)
|
# binding has to stay 'nil' for this to work!
|
||||||
|
initCandidate(c, m, s, nil)
|
||||||
|
|
||||||
|
for i in 1..sonsLen(n)-1:
|
||||||
|
let formal = s.ast.sons[genericParamsPos].sons[i-1].typ
|
||||||
|
let arg = n[i].typ
|
||||||
|
let tm = typeRel(m, formal, arg, true)
|
||||||
|
if tm in {isNone, isConvertible}:
|
||||||
|
if formal.sonsLen > 0 and formal.sons[0].kind != tyNone:
|
||||||
|
typeMismatch(n, formal.sons[0], arg)
|
||||||
|
else:
|
||||||
|
typeMismatch(n, formal, arg)
|
||||||
|
break
|
||||||
var newInst = generateInstance(c, s, m.bindings, n.info)
|
var newInst = generateInstance(c, s, m.bindings, n.info)
|
||||||
markUsed(n.info, s)
|
markUsed(n.info, s)
|
||||||
styleCheckUse(n.info, s)
|
styleCheckUse(n.info, s)
|
||||||
|
|
|
||||||
|
|
@ -1505,3 +1505,12 @@ proc skipHiddenSubConv*(n: PNode): PNode =
|
||||||
result.typ = dest
|
result.typ = dest
|
||||||
else:
|
else:
|
||||||
result = n
|
result = n
|
||||||
|
|
||||||
|
proc typeMismatch*(n: PNode, formal, actual: PType) =
|
||||||
|
if formal.kind != tyError and actual.kind != tyError:
|
||||||
|
let named = typeToString(formal)
|
||||||
|
let desc = typeToString(formal, preferDesc)
|
||||||
|
let x = if named == desc: named else: named & " = " & desc
|
||||||
|
localError(n.info, errGenerated, msgKindToString(errTypeMismatch) &
|
||||||
|
typeToString(actual) & ") " &
|
||||||
|
`%`(msgKindToString(errButExpectedX), [x]))
|
||||||
|
|
|
||||||
16
tests/generics/twrong_explicit_typeargs.nim
Normal file
16
tests/generics/twrong_explicit_typeargs.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "type mismatch: got (string) but expected 'int32 or int64'"
|
||||||
|
line: 16
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #4084
|
||||||
|
type
|
||||||
|
Image[T] = object
|
||||||
|
data: seq[T]
|
||||||
|
|
||||||
|
proc newImage[T: int32|int64](w, h: int): ref Image[T] =
|
||||||
|
new(result)
|
||||||
|
result.data = newSeq[T](w * h)
|
||||||
|
|
||||||
|
var correct = newImage[int32](320, 200)
|
||||||
|
var wrong = newImage[string](320, 200)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue