fixed incorrect implicit conversion between arrays of different sizes; see #202
This commit is contained in:
parent
254bc714dd
commit
b2814df5cd
2 changed files with 25 additions and 13 deletions
|
|
@ -374,19 +374,18 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||||
# tyArrayConstr cannot happen really, but
|
# tyArrayConstr cannot happen really, but
|
||||||
# we wanna be safe here
|
# we wanna be safe here
|
||||||
case a.kind
|
case a.kind
|
||||||
of tyArray:
|
of tyArray, tyArrayConstr:
|
||||||
result = minRel(typeRel(c, f.sons[0], a.sons[0]),
|
var fRange = f.sons[0]
|
||||||
typeRel(c, f.sons[1], a.sons[1]))
|
if fRange.kind == tyGenericParam:
|
||||||
if result < isGeneric: result = isNone
|
var prev = PType(idTableGet(c.bindings, fRange))
|
||||||
of tyArrayConstr:
|
if prev == nil:
|
||||||
result = typeRel(c, f.sons[1], a.sons[1])
|
put(c.bindings, fRange, a.sons[0])
|
||||||
if result < isGeneric:
|
fRange = a
|
||||||
result = isNone
|
|
||||||
else:
|
else:
|
||||||
if (result != isGeneric) and (lengthOrd(f) != lengthOrd(a)):
|
fRange = prev
|
||||||
result = isNone
|
result = typeRel(c, f.sons[1], a.sons[1])
|
||||||
elif f.sons[0].kind in GenericTypes:
|
if result < isGeneric: result = isNone
|
||||||
result = minRel(result, typeRel(c, f.sons[0], a.sons[0]))
|
elif lengthOrd(fRange) != lengthOrd(a): result = isNone
|
||||||
else: nil
|
else: nil
|
||||||
of tyOpenArray, tyVarargs:
|
of tyOpenArray, tyVarargs:
|
||||||
case a.Kind
|
case a.Kind
|
||||||
|
|
|
||||||
13
tests/reject/tarrayplus.nim
Normal file
13
tests/reject/tarrayplus.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
discard """
|
||||||
|
msg: "type mismatch: got (array[0..2, float], array[0..1, float])"
|
||||||
|
"""
|
||||||
|
|
||||||
|
proc `+`*[R, T] (v1, v2: array[R, T]): array[R, T] =
|
||||||
|
for i in low(v1)..high(v1):
|
||||||
|
result[i] = v1[i] + v2[i]
|
||||||
|
|
||||||
|
var
|
||||||
|
v1: array[0..2, float] = [3.0, 1.2, 3.0]
|
||||||
|
v2: array[0..1, float] = [2.0, 1.0]
|
||||||
|
v3 = v1 + v2
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue