From a1c217a2db6e3b263d4bc847d3f888f9ee63dc3c Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 30 Nov 2014 02:56:26 +0100 Subject: [PATCH] fixes #1684 --- compiler/sigmatch.nim | 4 ++++ tests/generics/tsubtypeconstraint.nim | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 tests/generics/tsubtypeconstraint.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 266236bf49..123d1df2ea 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -936,6 +936,10 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = else: if f.sonsLen > 0 and f.sons[0].kind != tyNone: result = typeRel(c, f.lastSon, a) + if doBind and result notin {isNone, isGeneric}: + let concrete = concreteType(c, a) + if concrete == nil: return isNone + put(c.bindings, f, concrete) else: result = isGeneric diff --git a/tests/generics/tsubtypeconstraint.nim b/tests/generics/tsubtypeconstraint.nim new file mode 100644 index 0000000000..2f09545220 --- /dev/null +++ b/tests/generics/tsubtypeconstraint.nim @@ -0,0 +1,13 @@ + +# bug #1684 +type + BaseType {.inheritable pure.} = object + idx: int + + DerivedType* {.final pure.} = object of BaseType + +proc index*[Toohoo: BaseType](h: Toohoo): int {.inline.} = h.idx +proc newDerived(idx: int): DerivedType {.inline.} = DerivedType(idx: idx) + +let d = newDerived(2) +assert(d.index == 2)