Skip to content

Commit d93b6a4

Browse files
committed
DiagnosticEngine: Do not describe an extension's nominal for %kindonly
This is the desired behavior is most cases. In the future, we should consider adding format specifiers for short/detailed descriptions.
1 parent 96be6cf commit d93b6a4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -875,21 +875,23 @@ static void formatDiagnosticArgument(StringRef Modifier,
875875
}
876876

877877
if (includeName) {
878-
// If it's an accessor, describe that and then switch to discussing its
879-
// storage.
880878
if (auto accessor = dyn_cast<AccessorDecl>(D)) {
879+
// If it's an accessor, describe that and then switch to discussing its
880+
// storage declaration.
881881
Out << Decl::getDescriptiveKindName(D->getDescriptiveKind()) << " for ";
882882
D = accessor->getStorage();
883+
} else if (auto ext = dyn_cast<ExtensionDecl>(D)) {
884+
// If it's an extension with a valid bound type declaration, describe
885+
// the extension itself then switch to discussing the bound
886+
// declaration.
887+
if (auto *nominal = ext->getSelfNominalTypeDecl()) {
888+
Out << Decl::getDescriptiveKindName(D->getDescriptiveKind())
889+
<< " of ";
890+
D = nominal;
891+
}
883892
}
884893
}
885894

886-
// If it's an extension, describe that and then switch to discussing its
887-
// nominal type.
888-
if (auto ext = dyn_cast<ExtensionDecl>(D)) {
889-
Out << Decl::getDescriptiveKindName(D->getDescriptiveKind()) << " of ";
890-
D = ext->getSelfNominalTypeDecl();
891-
}
892-
893895
// Figure out the name we want to print.
894896
DeclName name;
895897
if (includeName) {

0 commit comments

Comments
 (0)