Skip to content

Sema: Downgrade diagnostics about inheritance from a less available type when -target-min-inlining-version min is specified #59065

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
16 changes: 14 additions & 2 deletions lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1746,10 +1746,22 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
void visitNominalTypeDecl(const NominalTypeDecl *nominal) {
checkGenericParams(nominal, nominal);

DeclAvailabilityFlags flags =
DeclAvailabilityFlag::AllowPotentiallyUnavailableProtocol;

// As a concession to source compatibility for API libraries, downgrade
// diagnostics about inheritance from a less available type when the
// following conditions are met:
// 1. The inherited type is only potentially unavailable before the
// deployment target.
// 2. The inheriting type is `@usableFromInline`.
if (nominal->getAttrs().hasAttribute<UsableFromInlineAttr>())
flags |= DeclAvailabilityFlag::
WarnForPotentialUnavailabilityBeforeDeploymentTarget;

llvm::for_each(nominal->getInherited(), [&](TypeLoc inherited) {
checkType(inherited.getType(), inherited.getTypeRepr(), nominal,
ExportabilityReason::General,
DeclAvailabilityFlag::AllowPotentiallyUnavailableProtocol);
ExportabilityReason::General, flags);
});
}

Expand Down
5 changes: 5 additions & 0 deletions test/attr/attr_inlinable_available.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,11 @@ public enum NoAvailableEnumWithClasses {
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}}
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}}
public class InheritsAfterDeploymentTarget: AfterDeploymentTargetClass {} // expected-error {{'AfterDeploymentTargetClass' is only available in macOS 11 or newer}} expected-note 2 {{add @available attribute to enclosing class}}

// As a special case, downgrade the less available superclasses diagnostic for
// `@usableFromInline` classes.
@usableFromInline
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}}
}

@_spi(Private)
Expand Down