Skip to content

Commit 2795cc9

Browse files
committed
Reuse some unavailable diagnosis code in the type checker
This could still stand some more refactoring but reuses the renaming diagnostic.
1 parent 3661a0e commit 2795cc9

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,9 @@ using namespace swift;
3232
/// This requires the getter's body to have a certain syntactic form. It should
3333
/// be kept in sync with importEnumCaseAlias in the ClangImporter library.
3434
static EnumElementDecl *
35-
extractEnumElement(TypeChecker &TC, SourceLoc UseLoc, const VarDecl *constant) {
36-
if (auto Attr = AvailableAttr::isUnavailable(constant)) {
37-
auto Rename = Attr->Rename;
38-
if (!Rename.empty()) {
39-
TC.diagnose(UseLoc, diag::availability_decl_unavailable_rename,
40-
constant->getName(), /*replaced*/false,
41-
/*special kind*/0, Attr->Rename)
42-
.fixItReplace(UseLoc, Rename);
43-
}
44-
}
35+
extractEnumElement(TypeChecker &TC, DeclContext *DC, SourceLoc UseLoc,
36+
const VarDecl *constant) {
37+
TC.diagnoseExplicitUnavailability(constant, UseLoc, DC, nullptr);
4538

4639
const FuncDecl *getter = constant->getGetter();
4740
if (!getter)
@@ -72,7 +65,7 @@ extractEnumElement(TypeChecker &TC, SourceLoc UseLoc, const VarDecl *constant) {
7265
/// If there are no enum elements but there are properties, attempts to map
7366
/// an arbitrary property to an enum element using extractEnumElement.
7467
static EnumElementDecl *
75-
filterForEnumElement(TypeChecker &TC, SourceLoc UseLoc,
68+
filterForEnumElement(TypeChecker &TC, DeclContext *DC, SourceLoc UseLoc,
7669
LookupResult foundElements) {
7770
EnumElementDecl *foundElement = nullptr;
7871
VarDecl *foundConstant = nullptr;
@@ -97,7 +90,7 @@ filterForEnumElement(TypeChecker &TC, SourceLoc UseLoc,
9790
}
9891

9992
if (!foundElement && foundConstant && foundConstant->hasClangNode())
100-
foundElement = extractEnumElement(TC, UseLoc, foundConstant);
93+
foundElement = extractEnumElement(TC, DC, UseLoc, foundConstant);
10194

10295
return foundElement;
10396
}
@@ -109,7 +102,7 @@ lookupUnqualifiedEnumMemberElement(TypeChecker &TC, DeclContext *DC,
109102
auto lookupOptions = defaultUnqualifiedLookupOptions;
110103
lookupOptions |= NameLookupFlags::KnownPrivate;
111104
auto lookup = TC.lookupUnqualified(DC, name, SourceLoc(), lookupOptions);
112-
return filterForEnumElement(TC, UseLoc, lookup);
105+
return filterForEnumElement(TC, DC, UseLoc, lookup);
113106
}
114107

115108
/// Find an enum element in an enum type.
@@ -122,7 +115,7 @@ lookupEnumMemberElement(TypeChecker &TC, DeclContext *DC, Type ty,
122115
NameLookupOptions lookupOptions
123116
= defaultMemberLookupOptions - NameLookupFlags::DynamicLookup;
124117
LookupResult foundElements = TC.lookupMember(DC, ty, name, lookupOptions);
125-
return filterForEnumElement(TC, UseLoc, foundElements);
118+
return filterForEnumElement(TC, DC, UseLoc, foundElements);
126119
}
127120

128121
namespace {

0 commit comments

Comments
 (0)