Skip to content

Sema: Infer the availability of extensions using the extended type instead of just the nominal #59409

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
6 changes: 3 additions & 3 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,10 @@ class TypeRefinementContextBuilder : private ASTWalker {
// This rule is a convenience for library authors who have written
// extensions without specifying availabilty on the extension itself.
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
auto *Nominal = ED->getExtendedNominal();
if (Nominal && !hasActiveAvailableAttribute(D, Context)) {
auto ET = ED->getExtendedType();
if (ET && !hasActiveAvailableAttribute(D, Context)) {
EffectiveAvailability.intersectWith(
swift::AvailabilityInference::availableRange(Nominal, Context));
swift::AvailabilityInference::inferForType(ET));

// We want to require availability to be specified on extensions of
// types that would be potentially unavailable to the module containing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Foundation
// expected-provides {{NSObject}}
// expected-provides {{Selector}}
// expected-provides {{Bool}}
// expected-provides {{ObjCBool}}
// expected-provides {{==}}
// expected-provides {{Equatable}}
// expected-provides {{Hasher}}
Expand Down
30 changes: 30 additions & 0 deletions test/attr/attr_inlinable_available.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,36 @@ extension AfterDeploymentTarget {
) {}
}

// MARK: Extensions on nested types

@available(macOS 10.14.5, *)
public enum BetweenTargetsEnum {
public struct Nested {}
}

extension BetweenTargetsEnum.Nested {}

extension BetweenTargetsEnum.Nested { // expected-note {{add @available attribute to enclosing extension}}
func internalFuncInExtension( // expected-note {{add @available attribute to enclosing instance method}}
_: NoAvailable,
_: BeforeInliningTarget,
_: AtInliningTarget,
_: BetweenTargets,
_: AtDeploymentTarget,
_: AfterDeploymentTarget // expected-error {{'AfterDeploymentTarget' is only available in macOS 11 or newer}}
) {}
}

extension BetweenTargetsEnum.Nested { // expected-note 2 {{add @available attribute to enclosing extension}}
public func publicFuncInExtension( // expected-note 2 {{add @available attribute to enclosing instance method}}
_: NoAvailable,
_: BeforeInliningTarget,
_: AtInliningTarget,
_: BetweenTargets,
_: AtDeploymentTarget, // expected-error {{'AtDeploymentTarget' is only available in macOS 10.15 or newer; clients of 'Test' may have a lower deployment target}}
_: AfterDeploymentTarget // expected-error {{'AfterDeploymentTarget' is only available in macOS 11 or newer}}
) {}
}

// MARK: Protocol conformances

Expand Down