Skip to content

Commit 23e9719

Browse files
committed
Sema: Refactor "cannot be marked unavailable" diagnostics.
Make it possible to share the diagnostics string for common case.
1 parent da14b3c commit 23e9719

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6757,12 +6757,13 @@ WARNING(availability_query_useless_enclosing_scope, none,
67576757
NOTE(availability_query_useless_enclosing_scope_here, none,
67586758
"enclosing scope here", ())
67596759

6760-
ERROR(availability_deinit_no_potential, none,
6761-
"deinitializer cannot be marked potentially unavailable with "
6762-
"'@available'", ())
6760+
ERROR(availability_decl_no_potential, none,
6761+
"%kindonly0 cannot be marked potentially unavailable with '@available'",
6762+
(const Decl *))
67636763

6764-
ERROR(availability_deinit_no_unavailable, none,
6765-
"deinitializer cannot be marked unavailable with '@available'", ())
6764+
ERROR(availability_decl_no_unavailable, none,
6765+
"%kindonly0 cannot be marked unavailable with '@available'",
6766+
(const Decl *))
67666767

67676768
ERROR(availability_global_script_no_potential,
67686769
none, "global variable cannot be marked potentially "

lib/Sema/TypeCheckAttr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
22202220
}
22212221
}
22222222

2223-
std::optional<Diag<>> MaybeNotAllowed =
2223+
std::optional<Diagnostic> MaybeNotAllowed =
22242224
TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(D);
22252225
if (MaybeNotAllowed.has_value()) {
22262226
AvailabilityContext DeploymentRange
@@ -4924,13 +4924,13 @@ Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
49244924
return ReferenceStorageType::get(type, ownershipKind, var->getASTContext());
49254925
}
49264926

4927-
std::optional<Diag<>>
4927+
std::optional<Diagnostic>
49284928
TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
49294929
auto *DC = D->getDeclContext();
49304930

49314931
// A destructor is always called if declared.
49324932
if (auto *DD = dyn_cast<DestructorDecl>(D))
4933-
return diag::availability_deinit_no_potential;
4933+
return Diagnostic(diag::availability_decl_no_potential, D);
49344934

49354935
if (auto *VD = dyn_cast<VarDecl>(D)) {
49364936
if (!VD->hasStorageOrWrapsStorage())
@@ -4964,7 +4964,7 @@ TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
49644964
return std::nullopt;
49654965
}
49664966

4967-
std::optional<Diag<>>
4967+
std::optional<Diagnostic>
49684968
TypeChecker::diagnosticIfDeclCannotBeUnavailable(const Decl *D) {
49694969
auto parentIsUnavailable = [](const Decl *D) -> bool {
49704970
if (auto *parent =
@@ -4979,7 +4979,7 @@ TypeChecker::diagnosticIfDeclCannotBeUnavailable(const Decl *D) {
49794979
if (parentIsUnavailable(D))
49804980
return std::nullopt;
49814981

4982-
return diag::availability_deinit_no_unavailable;
4982+
return Diagnostic(diag::availability_decl_no_unavailable, D);
49834983
}
49844984

49854985
if (auto *VD = dyn_cast<VarDecl>(D)) {

lib/Sema/TypeChecker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,13 +1020,13 @@ TypeRefinementContext *getOrBuildTypeRefinementContext(SourceFile *SF);
10201020
/// Returns a diagnostic indicating why the declaration cannot be annotated
10211021
/// with an @available() attribute indicating it is potentially unavailable
10221022
/// or None if this is allowed.
1023-
std::optional<Diag<>>
1023+
std::optional<Diagnostic>
10241024
diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D);
10251025

10261026
/// Returns a diagnostic indicating why the declaration cannot be annotated
10271027
/// with an @available() attribute indicating it is unavailable or None if this
10281028
/// is allowed.
1029-
std::optional<Diag<>> diagnosticIfDeclCannotBeUnavailable(const Decl *D);
1029+
std::optional<Diagnostic> diagnosticIfDeclCannotBeUnavailable(const Decl *D);
10301030

10311031
/// Same as \c checkDeclarationAvailability but doesn't give a reason for
10321032
/// unavailability.

0 commit comments

Comments
 (0)