diff options
author | Zahary Karadjov <zahary@gmail.com> | 2014-03-19 22:35:31 +0200 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2014-03-20 01:16:50 +0200 |
commit | d508384d39461966ee247a01ad637bc57d3f62af (patch) | |
tree | a8907a0d45679aef4f251a44d2dd23fb7d6cd066 | |
parent | 4b7655fd10d81ea50d0af41152df07ec21b05232 (diff) | |
download | Nim-d508384d39461966ee247a01ad637bc57d3f62af.tar.gz |
fix #1013
-rw-r--r-- | compiler/sigmatch.nim | 14 | ||||
-rw-r--r-- | tests/matrix/issue1013.nim | 23 |
2 files changed, 33 insertions, 4 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 56490dfe3..c09964638 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -12,7 +12,7 @@ import intsets, ast, astalgo, semdata, types, msgs, renderer, lookups, semtypinst, - magicsys, condsyms, idents, lexer, options, parampatterns, strutils + magicsys, condsyms, idents, lexer, options, parampatterns, strutils, trees when not defined(noDocgen): import docgen @@ -973,11 +973,17 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = # fix the expression, so it contains the already instantiated types let instantiated = replaceTypesInBody(c.c, c.bindings, f.n) let reevaluted = c.c.semExpr(c.c, instantiated) - if reevaluted.typ.kind != tyTypeDesc: + case reevaluted.typ.kind + of tyTypeDesc: + result = typeRel(c, a, reevaluted.typ.base) + of tyStatic: + result = typeRel(c, a, reevaluted.typ.base) + if result != isNone and reevaluted.typ.n != nil: + if not exprStructuralEquivalent(aOrig.n, reevaluted.typ.n): + result = isNone + else: localError(f.n.info, errTypeExpected) result = isNone - else: - result = typeRel(c, a, reevaluted.typ.base) else: internalAssert false diff --git a/tests/matrix/issue1013.nim b/tests/matrix/issue1013.nim new file mode 100644 index 000000000..7d3d52f85 --- /dev/null +++ b/tests/matrix/issue1013.nim @@ -0,0 +1,23 @@ +import typetraits + +template reject(e: expr) = + static: assert(not compiles(e)) + +type + TMatrix[T; M, N: static[int]] = array[M*N, T] + +proc `*`[T; R, N, C](a: TMatrix[T, R, N], b: TMatrix[T, N, C]): TMatrix[T, R, C] = + discard + +var m1: TMatrix[int, 6, 4] +var m2: TMatrix[int, 4, 3] +var m3: TMatrix[int, 3, 3] + +var m4 = m1*m2 +static: assert m4.M == 6 and m4.N == 3 + +reject m1 * m3 # not compatible + +var m5 = m2 * m3 +static: assert high(m5) == 11 # 4*3 - 1 + |