Skip to content

Commit 8a71164

Browse files
[Diagnostics] Do not use canonical type for aka diagnostics instead visiting the type recursivelly desugaring
1 parent 843b25b commit 8a71164

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,6 @@ static bool shouldShowAKA(Type type, StringRef typeName) {
424424
if (type->isCanonical())
425425
return false;
426426

427-
// Don't show generic type parameters.
428-
if (type->getCanonicalType()->hasTypeParameter())
429-
return false;
430-
431427
// Only show 'aka' if there's a typealias involved; other kinds of sugar
432428
// are easy enough for people to read on their own.
433429
if (!type.findIf(isInterestingTypealias))
@@ -459,6 +455,20 @@ static bool typeSpellingIsAmbiguous(Type type,
459455
return false;
460456
}
461457

458+
/// Walks the type recursivelly desugaring types to display, but skiping
459+
/// `GenericTypeParamType` because we would lose association with it's original
460+
/// declaration and end up presenting the parameter in τ_0_0 format on
461+
/// diagnostic.
462+
static Type getAkaTypeForDisplay(Type type) {
463+
auto Func = [](Type visitTy) -> Type {
464+
if (isa<SugarType>(visitTy.getPointer()) &&
465+
!isa<GenericTypeParamType>(visitTy.getPointer()))
466+
return getAkaTypeForDisplay(visitTy->getDesugaredType());
467+
return visitTy;
468+
};
469+
return type.transform(Func).getPointer();
470+
}
471+
462472
/// Format a single diagnostic argument and write it to the given
463473
/// stream.
464474
static void formatDiagnosticArgument(StringRef Modifier,
@@ -577,7 +587,8 @@ static void formatDiagnosticArgument(StringRef Modifier,
577587
if (shouldShowAKA(type, typeName)) {
578588
llvm::SmallString<256> AkaText;
579589
llvm::raw_svector_ostream OutAka(AkaText);
580-
OutAka << type->getCanonicalType();
590+
591+
OutAka << getAkaTypeForDisplay(type);
581592
Out << llvm::format(FormatOpts.AKAFormatString.c_str(),
582593
typeName.c_str(), AkaText.c_str());
583594
} else {

0 commit comments

Comments
 (0)