Skip to content

Commit fe3c1e8

Browse files
committed
Sema: Downgrade over availability diagnostics to warnings for implicit decls.
It's likely that incorrect availability annotations on implicit decls represent compiler bugs, so downgrade the diagnostic to a warning to avoid blocking the developer. Resolves rdar://107764128
1 parent 4288ba9 commit fe3c1e8

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,8 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
18961896
}
18971897

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

@@ -1926,7 +1927,7 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
19261927
return;
19271928
}
19281929

1929-
if (auto *PD = dyn_cast<ProtocolDecl>(D->getDeclContext())) {
1930+
if (auto *PD = dyn_cast<ProtocolDecl>(DC)) {
19301931
if (auto *VD = dyn_cast<ValueDecl>(D)) {
19311932
if (VD->isProtocolRequirement() && !PD->isObjC()) {
19321933
diagnoseAndRemoveAttr(attr,
@@ -1958,13 +1959,17 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
19581959
EnclosingAnnotatedRange.emplace(
19591960
AvailabilityInference::availableRange(enclosingAttr, Ctx));
19601961
if (!AttrRange.isContainedIn(*EnclosingAnnotatedRange)) {
1961-
// Members of extensions of nominal types with available ranges were
1962-
// not diagnosed previously, so only emit a warning in that case.
1963-
bool inExtension = isa<ExtensionDecl>(
1964-
D->getDeclContext()->getTopmostDeclarationDeclContext());
1965-
auto limit = (enclosingDecl != parent && inExtension)
1966-
? DiagnosticBehavior::Warning
1967-
: DiagnosticBehavior::Unspecified;
1962+
auto limit = DiagnosticBehavior::Unspecified;
1963+
if (D->isImplicit()) {
1964+
// Incorrect availability for an implicit declaration is likely a
1965+
// compiler bug so make the diagnostic a warning.
1966+
limit = DiagnosticBehavior::Warning;
1967+
} else if (enclosingDecl != parent) {
1968+
// Members of extensions of nominal types with available ranges were
1969+
// not diagnosed previously, so only emit a warning in that case.
1970+
if (isa<ExtensionDecl>(DC->getTopmostDeclarationDeclContext()))
1971+
limit = DiagnosticBehavior::Warning;
1972+
}
19681973
diagnose(D->isImplicit() ? enclosingDecl->getLoc()
19691974
: attr->getLocation(),
19701975
diag::availability_decl_more_than_enclosing,

0 commit comments

Comments
 (0)