Skip to content

Commit 8cc2a55

Browse files
authored
Merge pull request swiftlang#59065 from tshortli/downgrade-inheritance-from-less-available-class-to-warning
2 parents 594d3ad + 7e40114 commit 8cc2a55

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,10 +1746,22 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
17461746
void visitNominalTypeDecl(const NominalTypeDecl *nominal) {
17471747
checkGenericParams(nominal, nominal);
17481748

1749+
DeclAvailabilityFlags flags =
1750+
DeclAvailabilityFlag::AllowPotentiallyUnavailableProtocol;
1751+
1752+
// As a concession to source compatibility for API libraries, downgrade
1753+
// diagnostics about inheritance from a less available type when the
1754+
// following conditions are met:
1755+
// 1. The inherited type is only potentially unavailable before the
1756+
// deployment target.
1757+
// 2. The inheriting type is `@usableFromInline`.
1758+
if (nominal->getAttrs().hasAttribute<UsableFromInlineAttr>())
1759+
flags |= DeclAvailabilityFlag::
1760+
WarnForPotentialUnavailabilityBeforeDeploymentTarget;
1761+
17491762
llvm::for_each(nominal->getInherited(), [&](TypeLoc inherited) {
17501763
checkType(inherited.getType(), inherited.getTypeRepr(), nominal,
1751-
ExportabilityReason::General,
1752-
DeclAvailabilityFlag::AllowPotentiallyUnavailableProtocol);
1764+
ExportabilityReason::General, flags);
17531765
});
17541766
}
17551767

test/attr/attr_inlinable_available.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,11 @@ public enum NoAvailableEnumWithClasses {
12901290
public class InheritsBetweenTargets: BetweenTargetsClass {} // expected-error {{'BetweenTargetsClass' is only available in macOS 10.14.5 or newer; clients of 'Test' may have a lower deployment target}} expected-note 2 {{add @available attribute to enclosing class}}
12911291
public class InheritsAtDeploymentTarget: AtDeploymentTargetClass {} // expected-error {{'AtDeploymentTargetClass' is only available in macOS 10.15 or newer; clients of 'Test' may have a lower deployment target}} expected-note 2 {{add @available attribute to enclosing class}}
12921292
public class InheritsAfterDeploymentTarget: AfterDeploymentTargetClass {} // expected-error {{'AfterDeploymentTargetClass' is only available in macOS 11 or newer}} expected-note 2 {{add @available attribute to enclosing class}}
1293+
1294+
// As a special case, downgrade the less available superclasses diagnostic for
1295+
// `@usableFromInline` classes.
1296+
@usableFromInline
1297+
class UFIInheritsBetweenTargets: BetweenTargetsClass {} // expected-warning {{'BetweenTargetsClass' is only available in macOS 10.14.5 or newer; clients of 'Test' may have a lower deployment target}} expected-note 2 {{add @available attribute to enclosing class}}
12931298
}
12941299

12951300
@_spi(Private)

0 commit comments

Comments
 (0)