Skip to content

Commit 52ee4ff

Browse files
authored
Merge pull request #17082 from slavapestov/inherited-availability-attribute-4.2
Sema: Fix availability of inherited designated initializers [4.2]
2 parents e594359 + 8cf1e3c commit 52ee4ff

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,9 +2037,12 @@ static void configureDesignatedInitAttributes(TypeChecker &tc,
20372037
ctor->getAttrs().add(clonedAttr);
20382038
}
20392039

2040-
// Make sure the constructor is only as available as its superclass's
2041-
// constructor.
2042-
AvailabilityInference::applyInferredAvailableAttrs(ctor, superclassCtor, ctx);
2040+
// If the superclass has its own availability, make sure the synthesized
2041+
// constructor is only as available as its superclass's constructor.
2042+
if (superclassCtor->getAttrs().hasAttribute<AvailableAttr>()) {
2043+
AvailabilityInference::applyInferredAvailableAttrs(
2044+
ctor, {classDecl, superclassCtor}, ctx);
2045+
}
20432046

20442047
if (superclassCtor->isObjC()) {
20452048
// Inherit the @objc name from the superclass initializer, if it

test/Sema/availability_versions.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,19 @@ func useUnavailableExtension() {
985985
// expected-note@-1 {{add 'if #available' version check}}
986986
}
987987

988+
// Availability of synthesized designated initializers.
989+
990+
@available(OSX, introduced: 10.51)
991+
class WidelyAvailableBase {
992+
init() {}
993+
994+
@available(OSX, introduced: 10.52)
995+
init(thing: ()) {}
996+
}
997+
998+
@available(OSX, introduced: 10.53)
999+
class EsotericSmallBatchHipsterThing : WidelyAvailableBase {}
1000+
9881001
// Useless #available(...) checks
9891002

9901003
func functionWithDefaultAvailabilityAndUselessCheck(_ p: Bool) {

0 commit comments

Comments
 (0)