Skip to content

Commit c4f833e

Browse files
committed
Run checkPatternBindingCaptures on Extensions
Resolves rdar://57348897
1 parent d31f6ed commit c4f833e

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,8 @@ static bool isLazy(PatternBindingDecl *PBD) {
660660
return false;
661661
}
662662

663-
void TypeChecker::checkPatternBindingCaptures(NominalTypeDecl *typeDecl) {
664-
auto &ctx = typeDecl->getASTContext();
665-
666-
for (auto member : typeDecl->getMembers()) {
663+
void TypeChecker::checkPatternBindingCaptures(IterableDeclContext *DC) {
664+
for (auto member : DC->getMembers()) {
667665
// Ignore everything other than PBDs.
668666
auto *PBD = dyn_cast<PatternBindingDecl>(member);
669667
if (!PBD) continue;

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
22652265
for (Decl *Member : ED->getMembers())
22662266
visit(Member);
22672267

2268+
TypeChecker::checkPatternBindingCaptures(ED);
2269+
22682270
TypeChecker::checkConformancesInContext(ED, ED);
22692271

22702272
TypeChecker::checkDeclAttributes(ED);

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ class TypeChecker final {
10461046
static void computeCaptures(AnyFunctionRef AFR);
10471047

10481048
/// Check for invalid captures from stored property initializers.
1049-
static void checkPatternBindingCaptures(NominalTypeDecl *typeDecl);
1049+
static void checkPatternBindingCaptures(IterableDeclContext *DC);
10501050

10511051
/// Change the context of closures in the given initializer
10521052
/// expression to the given context.

test/type/self.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ class C {
162162
}
163163
}
164164

165+
extension C {
166+
static var rdar57188331 = Self.staticFunc() // expected-error {{covariant 'Self' type cannot be referenced from a stored property initializer}} expected-error {{stored property cannot have covariant 'Self' type}}
167+
static var rdar57188331Var = ""
168+
static let rdar57188331Ref = UnsafeRawPointer(&Self.rdar57188331Var) // expected-error {{covariant 'Self' type cannot be referenced from a stored property initializer}}
169+
}
170+
171+
165172
struct S1 {
166173
typealias _SELF = Self
167174
let j = 99.1

0 commit comments

Comments
 (0)