Skip to content

Commit ab769cc

Browse files
committed
[CSSimplify] Determine whether type is know Foundation entity in a safer way
Instead of trying to get string representation of the type itself, let's just get it based on the type name, which works well with the list of types we have. Resolves: rdar://113675093 (cherry picked from commit b83a73d)
1 parent d649598 commit ab769cc

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,10 +2761,17 @@ assessRequirementFailureImpact(ConstraintSystem &cs, Type requirementType,
27612761
if (locator.isForRequirement(RequirementKind::Conformance)) {
27622762
// Increase the impact of a conformance fix for a standard library
27632763
// or foundation type, as it's unlikely to be a good suggestion.
2764-
if (resolvedTy->isStdlibType() ||
2765-
getKnownFoundationEntity(resolvedTy->getString())) {
2766-
impact += 2;
2764+
{
2765+
if (resolvedTy->isStdlibType()) {
2766+
impact += 2;
2767+
}
2768+
2769+
if (auto *NTD = resolvedTy->getAnyNominal()) {
2770+
if (getKnownFoundationEntity(NTD->getNameStr()))
2771+
impact += 2;
2772+
}
27672773
}
2774+
27682775
// Also do the same for the builtin compiler types Any and AnyObject, but
27692776
// bump the impact even higher as they cannot conform to protocols at all.
27702777
if (resolvedTy->isAny() || resolvedTy->isAnyObject())

0 commit comments

Comments
 (0)