diff options
-rwxr-xr-x | compiler/sigmatch.nim | 25 | ||||
-rw-r--r-- | tests/reject/tarrayplus.nim | 13 |
2 files changed, 25 insertions, 13 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 1f4c9653e..4d407fcb6 100755 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -370,23 +370,22 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation = of tyVar: if a.kind == f.kind: result = typeRel(c, base(f), base(a)) else: result = typeRel(c, base(f), a) - of tyArray, tyArrayConstr: + of tyArray, tyArrayConstr: # tyArrayConstr cannot happen really, but # we wanna be safe here case a.kind - of tyArray: - result = minRel(typeRel(c, f.sons[0], a.sons[0]), - typeRel(c, f.sons[1], a.sons[1])) - if result < isGeneric: result = isNone - of tyArrayConstr: + of tyArray, tyArrayConstr: + var fRange = f.sons[0] + if fRange.kind == tyGenericParam: + var prev = PType(idTableGet(c.bindings, fRange)) + if prev == nil: + put(c.bindings, fRange, a.sons[0]) + fRange = a + else: + fRange = prev result = typeRel(c, f.sons[1], a.sons[1]) - if result < isGeneric: - result = isNone - else: - if (result != isGeneric) and (lengthOrd(f) != lengthOrd(a)): - result = isNone - elif f.sons[0].kind in GenericTypes: - result = minRel(result, typeRel(c, f.sons[0], a.sons[0])) + if result < isGeneric: result = isNone + elif lengthOrd(fRange) != lengthOrd(a): result = isNone else: nil of tyOpenArray, tyVarargs: case a.Kind diff --git a/tests/reject/tarrayplus.nim b/tests/reject/tarrayplus.nim new file mode 100644 index 000000000..8c7452e85 --- /dev/null +++ b/tests/reject/tarrayplus.nim @@ -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 + |