Skip to content

Commit 1c7fa7e

Browse files
committed
Merge pull request #2004 from slavapestov/generic-super-capture-fix-2.2
Generic super capture fix (2.2)
2 parents e872a3c + 908fae0 commit 1c7fa7e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/Sema/TypeCheckExpr.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,13 @@ namespace {
798798
captureList[entryNumber-1] = capture;
799799
}
800800

801+
// Visit the type of the capture. If we capture 'self' via a 'super' call,
802+
// and the superclass is not generic, there might not be any generic
803+
// parameter types in the closure body, so we have to account for them
804+
// here.
805+
if (VD->hasType())
806+
checkType(VD->getType());
807+
801808
// If VD is a noescape decl, then the closure we're computing this for
802809
// must also be noescape.
803810
if (VD->getAttrs().hasAttribute<NoEscapeAttr>() &&

test/SILGen/closures.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,25 @@ class UnownedSelfNestedCapture {
542542
{[unowned self] in { self } }()()
543543
}
544544
}
545+
546+
// Check that capturing 'self' via a 'super' call also captures the generic
547+
// signature if the base class is concrete and the derived class is generic
548+
549+
class ConcreteBase {
550+
func swim() {}
551+
}
552+
553+
// CHECK-LABEL: sil shared @_TFFC8closures14GenericDerived4swimFT_T_U_FT_T_ : $@convention(thin) <Ocean> (@owned GenericDerived<Ocean>) -> ()
554+
// CHECK: [[SUPER:%.*]] = upcast %0 : $GenericDerived<Ocean> to $ConcreteBase
555+
// CHECK: [[METHOD:%.*]] = super_method %0 : $GenericDerived<Ocean>, #ConcreteBase.swim!1 : (ConcreteBase) -> () -> () , $@convention(method) (@guaranteed ConcreteBase) -> ()
556+
// CHECK: apply [[METHOD]]([[SUPER]]) : $@convention(method) (@guaranteed ConcreteBase) -> ()
557+
558+
class GenericDerived<Ocean> : ConcreteBase {
559+
override func swim() {
560+
withFlotationAid {
561+
super.swim()
562+
}
563+
}
564+
565+
func withFlotationAid(fn: () -> ()) {}
566+
}

0 commit comments

Comments
 (0)