Skip to content

[5.9] Sema: Downgrade over availability diagnostics to warnings for implicit decls #65013

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
23 changes: 14 additions & 9 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,8 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
}

// Skip the remaining diagnostics in swiftinterfaces.
auto *SF = D->getDeclContext()->getParentSourceFile();
auto *DC = D->getDeclContext();
auto *SF = DC->getParentSourceFile();
if (SF && SF->Kind == SourceFileKind::Interface)
return;

Expand Down Expand Up @@ -1926,7 +1927,7 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
return;
}

if (auto *PD = dyn_cast<ProtocolDecl>(D->getDeclContext())) {
if (auto *PD = dyn_cast<ProtocolDecl>(DC)) {
if (auto *VD = dyn_cast<ValueDecl>(D)) {
if (VD->isProtocolRequirement() && !PD->isObjC()) {
diagnoseAndRemoveAttr(attr,
Expand Down Expand Up @@ -1958,13 +1959,17 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
EnclosingAnnotatedRange.emplace(
AvailabilityInference::availableRange(enclosingAttr, Ctx));
if (!AttrRange.isContainedIn(*EnclosingAnnotatedRange)) {
// Members of extensions of nominal types with available ranges were
// not diagnosed previously, so only emit a warning in that case.
bool inExtension = isa<ExtensionDecl>(
D->getDeclContext()->getTopmostDeclarationDeclContext());
auto limit = (enclosingDecl != parent && inExtension)
? DiagnosticBehavior::Warning
: DiagnosticBehavior::Unspecified;
auto limit = DiagnosticBehavior::Unspecified;
if (D->isImplicit()) {
// Incorrect availability for an implicit declaration is likely a
// compiler bug so make the diagnostic a warning.
limit = DiagnosticBehavior::Warning;
} else if (enclosingDecl != parent) {
// Members of extensions of nominal types with available ranges were
// not diagnosed previously, so only emit a warning in that case.
if (isa<ExtensionDecl>(DC->getTopmostDeclarationDeclContext()))
limit = DiagnosticBehavior::Warning;
}
diagnose(D->isImplicit() ? enclosingDecl->getLoc()
: attr->getLocation(),
diag::availability_decl_more_than_enclosing,
Expand Down
14 changes: 12 additions & 2 deletions test/attr/attr_availability_maccatalyst_implicit.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -I %t -I %S/Inputs/custom-modules -parse-stdlib -parse-as-library -typecheck -verify -target x86_64-apple-ios15.4-macabi %s
// RUN: %target-swift-frontend -I %t -I %S/Inputs/custom-modules -parse-stdlib -parse-as-library -typecheck -verify -target %target-cpu-apple-ios15.4-macabi %s

// REQUIRES: objc_interop
// REQUIRES: maccatalyst_support
Expand All @@ -7,7 +7,17 @@ import Available_NSObject

@available(iOS 15.0, *)
open class OverAvailableClass: NSBaseClass {}
// expected-error@-1 {{initializer cannot be more available than enclosing scope}}
// expected-warning@-1 {{initializer cannot be more available than enclosing scope}}
// expected-note@-2 {{initializer implicitly declared here with availability of Mac Catalyst 13.1 or newer}}
// expected-note@-3 {{enclosing scope requires availability of Mac Catalyst 15.0 or newer}}

extension NSBaseClass {
@available(iOS 15.0, *)
// expected-warning@+3 {{_modify accessor cannot be more available than enclosing scope}}
// expected-note@+2 {{_modify accessor implicitly declared here with availability of Mac Catalyst 13.1 or newer}}
// expected-note@+1 {{enclosing scope requires availability of Mac Catalyst 15.0 or newer}}
var property: Int {
get { 1 }
set {}
}
}