Skip to content

Generic super capture fix (2.2) #2004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/Sema/TypeCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,13 @@ namespace {
captureList[entryNumber-1] = capture;
}

// Visit the type of the capture. If we capture 'self' via a 'super' call,
// and the superclass is not generic, there might not be any generic
// parameter types in the closure body, so we have to account for them
// here.
if (VD->hasType())
checkType(VD->getType());

// If VD is a noescape decl, then the closure we're computing this for
// must also be noescape.
if (VD->getAttrs().hasAttribute<NoEscapeAttr>() &&
Expand Down
22 changes: 22 additions & 0 deletions test/SILGen/closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -542,3 +542,25 @@ class UnownedSelfNestedCapture {
{[unowned self] in { self } }()()
}
}

// Check that capturing 'self' via a 'super' call also captures the generic
// signature if the base class is concrete and the derived class is generic

class ConcreteBase {
func swim() {}
}

// CHECK-LABEL: sil shared @_TFFC8closures14GenericDerived4swimFT_T_U_FT_T_ : $@convention(thin) <Ocean> (@owned GenericDerived<Ocean>) -> ()
// CHECK: [[SUPER:%.*]] = upcast %0 : $GenericDerived<Ocean> to $ConcreteBase
// CHECK: [[METHOD:%.*]] = super_method %0 : $GenericDerived<Ocean>, #ConcreteBase.swim!1 : (ConcreteBase) -> () -> () , $@convention(method) (@guaranteed ConcreteBase) -> ()
// CHECK: apply [[METHOD]]([[SUPER]]) : $@convention(method) (@guaranteed ConcreteBase) -> ()

class GenericDerived<Ocean> : ConcreteBase {
override func swim() {
withFlotationAid {
super.swim()
}
}

func withFlotationAid(fn: () -> ()) {}
}