Skip to content

Commit 446a824

Browse files
committed
Don't infer 'dynamic' on accessors in extensions of ObjC classes.
Instead, propagate the decision from the associated storage decl (var or subscript), using the mechanisms that are already in place. rdar://problem/29741743
1 parent 05d41ae commit 446a824

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,12 @@ static void inferDynamic(ASTContext &ctx, ValueDecl *D) {
22272227
if (VD->isLet() && !isNSManaged) return;
22282228
}
22292229

2230+
// Accessors should not infer 'dynamic' on their own; they can get it from
2231+
// their storage decls.
2232+
if (auto FD = dyn_cast<FuncDecl>(D))
2233+
if (FD->isAccessor())
2234+
return;
2235+
22302236
// The presence of 'final' on a class prevents 'dynamic'.
22312237
auto classDecl = D->getDeclContext()->getAsClassOrClassExtensionContext();
22322238
if (!classDecl) return;
@@ -3810,6 +3816,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
38103816
if (isObjC && !TC.isRepresentableInObjC(SD, *isObjC))
38113817
isObjC = None;
38123818
markAsObjC(TC, SD, isObjC);
3819+
3820+
// Infer 'dynamic' before touching accessors.
3821+
inferDynamic(TC.Context, SD);
38133822
}
38143823

38153824
if (SD->hasAccessorFunctions())
@@ -3838,8 +3847,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
38383847
synthesizeSetterForMutableAddressedStorage(SD, TC);
38393848
}
38403849

3841-
inferDynamic(TC.Context, SD);
3842-
38433850
TC.checkDeclAttributes(SD);
38443851
}
38453852

@@ -7015,6 +7022,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
70157022

70167023
markAsObjC(*this, VD, isObjC);
70177024

7025+
// Infer 'dynamic' before touching accessors.
70187026
inferDynamic(Context, VD);
70197027

70207028
// If this variable is a class member, mark it final if the

test/attr/attr_dynamic_infer.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,28 @@ extension Sub {
5454
override func baseFoo() {
5555
}
5656
}
57+
58+
59+
@objc class FinalTests {}
60+
61+
extension FinalTests {
62+
// CHECK: @objc final func foo
63+
final func foo() { }
64+
65+
// CHECK: @objc final var prop: Super
66+
final var prop: Super {
67+
// CHECK: @objc final get
68+
get { return Super() }
69+
// CHECK: @objc final set
70+
set { }
71+
}
72+
73+
// CHECK: @objc final subscript(sup: Super) -> Super
74+
final subscript(sup: Super) -> Super {
75+
// CHECK: @objc final get
76+
get { return sup }
77+
// CHECK: @objc final set
78+
set { }
79+
}
80+
}
81+

0 commit comments

Comments
 (0)