From c9513c2e5a42e6a34e11568a708d3db80d2b6283 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 19 Jul 2012 08:41:57 +0200 Subject: [PATCH] bugfix: constraint matching for tyGenericInst; implements #130 --- compiler/semtypes.nim | 9 ++++++++- compiler/sigmatch.nim | 2 +- tests/compile/tloops.nim | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index e9cb8babbc..3aafd2492e 100755 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -198,7 +198,14 @@ proc semTypeIdent(c: PContext, n: PNode): PSym = return result.typ.sym else: return result.typ.sym - if result.kind != skType: GlobalError(n.info, errTypeExpected) + if result.kind != skType: + # this implements the wanted ``var v: V, x: V`` feature ... + var ov: TOverloadIter + var amb = InitOverloadIter(ov, c, n) + while amb != nil and amb.kind != skType: + amb = nextOverloadIter(ov, c, n) + if amb != nil: result = amb + else: GlobalError(n.info, errTypeExpected) if result.typ.kind != tyGenericParam: # XXX get rid of this hack! reset(n[]) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index af924bafe4..6021d27ab7 100755 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -249,7 +249,7 @@ proc tupleRel(c: var TCandidate, f, a: PType): TTypeRelation = proc matchTypeClass(c: var TCandidate, f, a: PType): TTypeRelation = for i in countup(0, f.sonsLen - 1): let son = f.sons[i] - var match = son.kind == skipTypes(a, {tyRange}).kind + var match = son.kind == skipTypes(a, {tyRange, tyGenericInst}).kind if not match: case son.kind diff --git a/tests/compile/tloops.nim b/tests/compile/tloops.nim index 74a3992c9b..2b1765b007 100755 --- a/tests/compile/tloops.nim +++ b/tests/compile/tloops.nim @@ -62,3 +62,26 @@ proc Foo(n: int): int = # We should come till here :-) discard Foo(345) + +# test the new type symbol lookup feature: + +type + MyType[T] = tuple[ + x, y, z: T] + MyType2 = tuple[x, y: float] + +proc main[T]() = + var myType: MyType[T] + var b: MyType[T] + b = (1, 2, 3) + myType = b + echo myType + + var myType2: MyType2 + var c: MyType2 + c = (1.0, 2.0) + myType2 = c + echo myType2 + +main[int]() +