Skip to content

Sema: Fix availability of inherited designated initializers [4.2] #17082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,9 +2037,12 @@ static void configureDesignatedInitAttributes(TypeChecker &tc,
ctor->getAttrs().add(clonedAttr);
}

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

if (superclassCtor->isObjC()) {
// Inherit the @objc name from the superclass initializer, if it
Expand Down
13 changes: 13 additions & 0 deletions test/Sema/availability_versions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,19 @@ func useUnavailableExtension() {
// expected-note@-1 {{add 'if #available' version check}}
}

// Availability of synthesized designated initializers.

@available(OSX, introduced: 10.51)
class WidelyAvailableBase {
init() {}

@available(OSX, introduced: 10.52)
init(thing: ()) {}
}

@available(OSX, introduced: 10.53)
class EsotericSmallBatchHipsterThing : WidelyAvailableBase {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! Can you add a test in the opposite direction, where the initializer is 10.53 and the subclass is 10.52? (I know that would break a lot of other things too, but we should have a test for it anyway.)


// Useless #available(...) checks

func functionWithDefaultAvailabilityAndUselessCheck(_ p: Bool) {
Expand Down