Skip to content

Commit 8a02f6f

Browse files
committed
Sema: Infer the availability of extensions without explicit availability using the extended type instead of just the nominal.
This ensures availability is inferred correctly for nested types. Resolves rdar://94851069
1 parent 0909728 commit 8a02f6f

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-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/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)