Skip to content

Commit 0e9bef2

Browse files
authored
Merge pull request #59409 from tshortli/inferred-availability-for-extensions-of-nested-types
Sema: Infer the availability of extensions using the extended type instead of just the nominal
2 parents a845fa5 + 7ee5986 commit 0e9bef2

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ class TypeRefinementContextBuilder : private ASTWalker {
582582
// This rule is a convenience for library authors who have written
583583
// extensions without specifying availabilty on the extension itself.
584584
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
585-
auto *Nominal = ED->getExtendedNominal();
586-
if (Nominal && !hasActiveAvailableAttribute(D, Context)) {
585+
auto ET = ED->getExtendedType();
586+
if (ET && !hasActiveAvailableAttribute(D, Context)) {
587587
EffectiveAvailability.intersectWith(
588-
swift::AvailabilityInference::availableRange(Nominal, Context));
588+
swift::AvailabilityInference::inferForType(ET));
589589

590590
// We want to require availability to be specified on extensions of
591591
// types that would be potentially unavailable to the module containing

test/Incremental/Verifier/single-file-private/AnyObject.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Foundation
1616
// expected-provides {{NSObject}}
1717
// expected-provides {{Selector}}
1818
// expected-provides {{Bool}}
19+
// expected-provides {{ObjCBool}}
1920
// expected-provides {{==}}
2021
// expected-provides {{Equatable}}
2122
// expected-provides {{Hasher}}

test/attr/attr_inlinable_available.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,36 @@ extension AfterDeploymentTarget {
11341134
) {}
11351135
}
11361136

1137+
// MARK: Extensions on nested types
1138+
1139+
@available(macOS 10.14.5, *)
1140+
public enum BetweenTargetsEnum {
1141+
public struct Nested {}
1142+
}
1143+
1144+
extension BetweenTargetsEnum.Nested {}
1145+
1146+
extension BetweenTargetsEnum.Nested { // expected-note {{add @available attribute to enclosing extension}}
1147+
func internalFuncInExtension( // expected-note {{add @available attribute to enclosing instance method}}
1148+
_: NoAvailable,
1149+
_: BeforeInliningTarget,
1150+
_: AtInliningTarget,
1151+
_: BetweenTargets,
1152+
_: AtDeploymentTarget,
1153+
_: AfterDeploymentTarget // expected-error {{'AfterDeploymentTarget' is only available in macOS 11 or newer}}
1154+
) {}
1155+
}
1156+
1157+
extension BetweenTargetsEnum.Nested { // expected-note 2 {{add @available attribute to enclosing extension}}
1158+
public func publicFuncInExtension( // expected-note 2 {{add @available attribute to enclosing instance method}}
1159+
_: NoAvailable,
1160+
_: BeforeInliningTarget,
1161+
_: AtInliningTarget,
1162+
_: BetweenTargets,
1163+
_: AtDeploymentTarget, // expected-error {{'AtDeploymentTarget' is only available in macOS 10.15 or newer; clients of 'Test' may have a lower deployment target}}
1164+
_: AfterDeploymentTarget // expected-error {{'AfterDeploymentTarget' is only available in macOS 11 or newer}}
1165+
) {}
1166+
}
11371167

11381168
// MARK: Protocol conformances
11391169

0 commit comments

Comments
 (0)