Skip to content

Commit f273e3a

Browse files
committed
Sema: Fix availability of inherited designated initializers, part 2
We need to explicitly handle nested types here. Fixes the (re-opened) <rdar://problem/40853731>, <https://bugs.swift.org/browse/SR-7881>.
1 parent e325e32 commit f273e3a

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,9 +2152,16 @@ static void configureDesignatedInitAttributes(TypeChecker &tc,
21522152

21532153
// If the superclass has its own availability, make sure the synthesized
21542154
// constructor is only as available as its superclass's constructor.
2155-
if (superclassCtor->getAttrs().hasAttribute<AvailableAttr>()) {
2155+
{
2156+
SmallVector<Decl *, 2> asAvailableAs;
2157+
asAvailableAs.push_back(superclassCtor);
2158+
Decl *parentDecl = classDecl;
2159+
while (parentDecl != nullptr) {
2160+
asAvailableAs.push_back(parentDecl);
2161+
parentDecl = parentDecl->getDeclContext()->getAsDeclOrDeclExtensionContext();
2162+
}
21562163
AvailabilityInference::applyInferredAvailableAttrs(
2157-
ctor, {classDecl, superclassCtor}, ctx);
2164+
ctor, asAvailableAs, ctx);
21582165
}
21592166

21602167
if (superclassCtor->isObjC()) {

test/Sema/availability_versions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,11 @@ class WidelyAvailableBase {
998998
@available(OSX, introduced: 10.53)
999999
class EsotericSmallBatchHipsterThing : WidelyAvailableBase {}
10001000

1001+
@available(OSX, introduced: 10.53)
1002+
class NestedClassTest {
1003+
class InnerClass : WidelyAvailableBase {}
1004+
}
1005+
10011006
// Useless #available(...) checks
10021007

10031008
func functionWithDefaultAvailabilityAndUselessCheck(_ p: Bool) {

test/Sema/availability_versions_multi.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ func useFromOtherOn10_51() {
3535
_ = o10_51.returns10_52Introduced10_52() // expected-error {{'returns10_52Introduced10_52()' is only available on OS X 10.52 or newer}}
3636
// expected-note@-1 {{add 'if #available' version check}}
3737

38-
_ = OtherIntroduced10_52() // expected-error {{'OtherIntroduced10_52' is only available on OS X 10.52 or newer}}
39-
// expected-note@-1 {{add 'if #available' version check}}
38+
_ = OtherIntroduced10_52()
39+
// expected-error@-1 {{'OtherIntroduced10_52' is only available on OS X 10.52 or newer}}
40+
// expected-error@-2 {{'init()' is only available on OS X 10.52 or newer}}
41+
// expected-note@-3 {{add 'if #available' version check}}
42+
// expected-note@-4 {{add 'if #available' version check}}
4043

4144
o10_51.extensionMethodOnOtherIntroduced10_51AvailableOn10_52() // expected-error {{'extensionMethodOnOtherIntroduced10_51AvailableOn10_52()' is only available on OS X 10.52 or newer}}
4245
// expected-note@-1 {{add 'if #available' version check}}
4346

44-
_ = OtherIntroduced10_51.NestedIntroduced10_52() // expected-error {{'NestedIntroduced10_52' is only available on OS X 10.52 or newer}}
45-
// expected-note@-1 {{add 'if #available' version check}}
47+
_ = OtherIntroduced10_51.NestedIntroduced10_52()
48+
// expected-error@-1 {{'NestedIntroduced10_52' is only available on OS X 10.52 or newer}}
49+
// expected-error@-2 {{'init()' is only available on OS X 10.52 or newer}}
50+
// expected-note@-3 {{add 'if #available' version check}}
51+
// expected-note@-4 {{add 'if #available' version check}}
4652
}
4753

4854
@available(OSX, introduced: 10.52)

0 commit comments

Comments
 (0)