Skip to content

Commit 44227fe

Browse files
committed
Add test cases for when a property/subscript is redeclared readwrite
And improve the comment around the FIXME for this, which is tricky to implement.
1 parent 406a9d9 commit 44227fe

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,10 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
17121712
}
17131713

17141714
// FIXME: Check storage decls where the setter is in a separate module from
1715-
// the getter, which is a thing Objective-C can do.
1715+
// the getter, which is a thing Objective-C can do. The ClangImporter
1716+
// doesn't make this easy, though, because it just gives the setter the same
1717+
// DeclContext as the property or subscript, which means we've lost the
1718+
// information about whether its module was implementation-only imported.
17161719
}
17171720

17181721
void visit(Decl *D) {

test/Sema/Inputs/implementation-only-override/FooKit.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33

44
@interface Parent : Base
55
- (nonnull instancetype)init __attribute__((objc_designated_initializer));
6+
7+
// The SECRET is on a non-secret property here because we need to enforce that
8+
// it's not printed.
9+
@property (readonly, strong, nullable) Parent *redefinedPropSECRET;
610
@end
711

812
@interface GenericParent<T: Base *> : Base
913
- (nonnull instancetype)init __attribute__((objc_designated_initializer));
1014
@end
15+
16+
@interface SubscriptParent : Base
17+
- (nullable Parent *)objectAtIndexedSubscript:(int)index;
18+
@end

test/Sema/Inputs/implementation-only-override/FooKit_SECRET.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@property (readwrite, strong, nullable) Parent *rwPropSECRET;
1414

1515
- (nullable Parent *)objectAtIndexedSubscript:(int)index;
16+
17+
@property (readwrite, strong, nullable) Parent *redefinedPropSECRET;
1618
@end
1719

1820
@protocol MandatorySecrets
@@ -27,3 +29,7 @@
2729
@property (readonly, strong, nullable) T roPropSECRET;
2830
- (nullable Parent *)objectAtIndexedSubscript:(int)index;
2931
@end
32+
33+
@interface SubscriptParent ()
34+
- (void)setObject:(nullable Parent *)object atIndexedSubscript:(int)index;
35+
@end

test/Sema/implementation-only-override.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public class GoodChild: Parent {
3131
set {}
3232
}
3333
@_implementationOnly public override subscript(_ index: Int32) -> Parent? { nil } // expected-note {{overridden declaration is here}}
34+
@_implementationOnly public override var redefinedPropSECRET: Parent? { // expected-note {{overridden declaration is here}}
35+
get { nil }
36+
set {}
37+
}
3438
}
3539

3640
// CHECK-LABEL: class QuietChild : FooKit.Parent {
@@ -76,6 +80,10 @@ internal class PrivateChild: Parent {
7680
set {}
7781
}
7882
override subscript(_ index: Int32) -> Parent? { nil }
83+
override var redefinedPropSECRET: Parent? {
84+
get { nil }
85+
set {}
86+
}
7987
}
8088

8189
internal class PrivateGrandchild: GoodChild {
@@ -87,6 +95,20 @@ internal class PrivateGrandchild: GoodChild {
8795
set {}
8896
}
8997
override subscript(_ index: Int32) -> Parent? { nil }
98+
override var redefinedPropSECRET: Parent? {
99+
get { nil }
100+
set {}
101+
}
102+
}
103+
104+
// CHECK-LABEL: class SubscriptChild : FooKit.SubscriptParent {
105+
// CHECK-NEXT: @objc deinit
106+
// CHECK-NEXT: }
107+
public class SubscriptChild: SubscriptParent {
108+
@_implementationOnly public override subscript(_ index: Int32) -> Parent? {
109+
get { nil }
110+
set {}
111+
}
90112
}
91113

92114
#if ERRORS
@@ -107,6 +129,10 @@ public class NaughtyChild: Parent {
107129
set {}
108130
}
109131
public override subscript(_ index: Int32) -> Parent? { nil } // expected-error {{override of subscript imported as implementation-only must be declared '@_implementationOnly'}} {{3-3=@_implementationOnly }}
132+
public override var redefinedPropSECRET: Parent? { // FIXME: the setter here is from the implementation-only import, so we'd like to complain about this too.
133+
get { nil }
134+
set {}
135+
}
110136
}
111137

112138
public class NaughtyChildByType: Parent {
@@ -128,6 +154,10 @@ public class NaughtyGrandchild: GoodChild {
128154
set {}
129155
}
130156
public override subscript(_ index: Int32) -> Parent? { nil } // expected-error {{override of '@_implementationOnly' subscript should also be declared '@_implementationOnly'}} {{3-3=@_implementationOnly }}
157+
public override var redefinedPropSECRET: Parent? { // expected-error {{override of '@_implementationOnly' property should also be declared '@_implementationOnly'}} {{3-3=@_implementationOnly }}
158+
get { nil }
159+
set {}
160+
}
131161
}
132162

133163
#endif // ERRORS

0 commit comments

Comments
 (0)