Skip to content

Commit 5bdf189

Browse files
committed
Sema: Remove a usage of hasComputedGenericSignature() from expression checker diagnostics
Removing this exposed a re-entrant diagnostic emission, so let's fix that too.
1 parent c3a7d98 commit 5bdf189

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,13 +1840,9 @@ bool TypeChecker::getDefaultGenericArgumentsString(
18401840
genericParamText << contextTy;
18411841
};
18421842

1843-
// FIXME: We can potentially be in the middle of creating a generic signature
1844-
// if we get here. Break this cycle.
1845-
if (typeDecl->hasComputedGenericSignature()) {
1846-
llvm::interleave(typeDecl->getInnermostGenericParamTypes(),
1847-
printGenericParamSummary,
1848-
[&] { genericParamText << ", "; });
1849-
}
1843+
llvm::interleave(typeDecl->getInnermostGenericParamTypes(),
1844+
printGenericParamSummary,
1845+
[&] { genericParamText << ", "; });
18501846

18511847
genericParamText << ">";
18521848
return true;

lib/Sema/TypeCheckType.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -996,11 +996,17 @@ static void diagnoseUnboundGenericType(Type ty, SourceLoc loc) {
996996
if (auto unbound = ty->getAs<UnboundGenericType>()) {
997997
auto *decl = unbound->getDecl();
998998
{
999-
InFlightDiagnostic diag = ctx.Diags.diagnose(loc,
1000-
diag::generic_type_requires_arguments, ty);
999+
// Compute the string before creating a new diagnostic, since
1000+
// getDefaultGenericArgumentsString() might emit its own
1001+
// diagnostics.
10011002
SmallString<64> genericArgsToAdd;
1002-
if (TypeChecker::getDefaultGenericArgumentsString(genericArgsToAdd,
1003-
decl))
1003+
bool hasGenericArgsToAdd =
1004+
TypeChecker::getDefaultGenericArgumentsString(genericArgsToAdd,
1005+
decl);
1006+
1007+
auto diag = ctx.Diags.diagnose(loc,
1008+
diag::generic_type_requires_arguments, ty);
1009+
if (hasGenericArgsToAdd)
10041010
diag.fixItInsertAfter(loc, genericArgsToAdd);
10051011
}
10061012

0 commit comments

Comments
 (0)