Skip to content

Commit 6818207

Browse files
committed
[NFC] Sema/TypeCheckAvailability: Refactor for recursive MemberTypeRepr representation
1 parent fe7cb56 commit 6818207

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3877,11 +3877,20 @@ class TypeReprAvailabilityWalker : public ASTWalker {
38773877
const ExportContext &where;
38783878
DeclAvailabilityFlags flags;
38793879

3880-
bool checkIdentTypeRepr(IdentTypeRepr *ITR) {
3880+
bool checkDeclRefTypeRepr(DeclRefTypeRepr *declRefTR) const {
38813881
ArrayRef<AssociatedTypeDecl *> primaryAssociatedTypes;
38823882

3883-
if (auto *typeDecl = ITR->getBoundDecl()) {
3884-
auto range = ITR->getNameLoc().getSourceRange();
3883+
if (auto *memberTR = dyn_cast<MemberTypeRepr>(declRefTR)) {
3884+
// If the base is unavailable, don't go on to diagnose
3885+
// the member since that will just produce a redundant
3886+
// diagnostic.
3887+
if (diagnoseTypeReprAvailability(memberTR->getBase(), where, flags)) {
3888+
return true;
3889+
}
3890+
}
3891+
3892+
if (auto *typeDecl = declRefTR->getBoundDecl()) {
3893+
auto range = declRefTR->getNameLoc().getSourceRange();
38853894
if (diagnoseDeclAvailability(typeDecl, range, nullptr, where, flags))
38863895
return true;
38873896

@@ -3892,7 +3901,7 @@ class TypeReprAvailabilityWalker : public ASTWalker {
38923901

38933902
bool foundAnyIssues = false;
38943903

3895-
if (auto *GTR = dyn_cast<GenericIdentTypeRepr>(ITR)) {
3904+
if (auto *GTR = dyn_cast<GenericIdentTypeRepr>(declRefTR)) {
38963905
auto genericFlags = flags;
38973906
genericFlags -= DeclAvailabilityFlag::AllowPotentiallyUnavailableProtocol;
38983907

@@ -3932,27 +3941,8 @@ class TypeReprAvailabilityWalker : public ASTWalker {
39323941
if (!declRefTR)
39333942
return Action::Continue();
39343943

3935-
auto *rootComp = declRefTR->getRoot();
3936-
if (auto *identBase = dyn_cast<IdentTypeRepr>(rootComp)) {
3937-
if (checkIdentTypeRepr(identBase)) {
3938-
foundAnyIssues = true;
3939-
return Action::SkipNode();
3940-
}
3941-
} else if (diagnoseTypeReprAvailability(rootComp, where, flags)) {
3944+
if (checkDeclRefTypeRepr(declRefTR)) {
39423945
foundAnyIssues = true;
3943-
return Action::SkipNode();
3944-
}
3945-
3946-
if (auto *memberTR = dyn_cast<MemberTypeRepr>(T)) {
3947-
for (auto *comp : memberTR->getMemberComponents()) {
3948-
// If a parent type is unavailable, don't go on to diagnose
3949-
// the member since that will just produce a redundant
3950-
// diagnostic.
3951-
if (checkIdentTypeRepr(comp)) {
3952-
foundAnyIssues = true;
3953-
break;
3954-
}
3955-
}
39563946
}
39573947

39583948
// We've already visited all the children above, so we don't

0 commit comments

Comments
 (0)