From 3e52bb6535a70339cf4a15123be09916ef0c31f6 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Tue, 18 Apr 2017 23:55:59 +0300 Subject: [PATCH] fix a regrsesion in signature matching of derived ptr types --- compiler/sigmatch.nim | 8 +++++--- tests/generics/tptrinheritance.nim | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/generics/tptrinheritance.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index a8551fa194..d6a0c6382e 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1240,13 +1240,15 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = if prev == nil: put(c, f, a) result = isGeneric else: - var aAsObject = roota.lastSon - if rootf.lastSon.kind in {tyAnd, tyOr}: + let fKind = rootf.lastSon.kind + if fKind in {tyAnd, tyOr}: result = typeRel(c, lastSon(f), a) if result != isNone: put(c, f, a) return - if rootf.lastSon.kind == tyRef and aAsObject.kind == tyRef: + var aAsObject = roota.lastSon + + if fKind in {tyRef, tyPtr} and aAsObject.kind == fKind: aAsObject = aAsObject.base if aAsObject.kind == tyObject: diff --git a/tests/generics/tptrinheritance.nim b/tests/generics/tptrinheritance.nim new file mode 100644 index 0000000000..1e1115fa56 --- /dev/null +++ b/tests/generics/tptrinheritance.nim @@ -0,0 +1,20 @@ +type NSPasteboardItem* = ptr object +type NSPasteboard* = ptr object +type NSArrayAbstract = ptr object {.inheritable.} +type NSMutableArrayAbstract = ptr object of NSArrayAbstract +type NSArray*[T] = ptr object of NSArrayAbstract +type NSMutableArray*[T] = ptr object of NSArray[T] + +proc newMutableArrayAbstract*(): NSMutableArrayAbstract = discard + +template newMutableArray*(T: typedesc): NSMutableArray[T] = + cast[NSMutableArray[T]](newMutableArrayAbstract()) + +proc writeObjects*(p: NSPasteboard, o: ptr NSArray[NSPasteboardItem]) = discard + +let a = newMutableArray NSPasteboardItem +var x: NSMutableArray[NSPasteboardItem] +var y: NSArray[NSPasteboardItem] = x + +writeObjects(nil, a) +