Revert "[ConstraintSystem] C++ Interop: Binding a string literal to std.string shouldn't increase the score"

This reverts commit cd9c37ca

This is causing build failures for some projects. We need more time to investigate. Reverting this temporarily in the meantime.

rdar://158439395
This commit is contained in:
Egor Zhdan
2025-11-05 11:19:11 -08:00
parent 2b4737585d
commit 6852bc9834
6 changed files with 4 additions and 75 deletions

View File

@@ -257,28 +257,11 @@ void ConstraintSystem::assignFixedType(TypeVariableType *typeVar, Type type,
// If the protocol has a default type, check it.
if (auto defaultType = TypeChecker::getDefaultType(literalProtocol, DC)) {
auto isDefaultType = [&literalProtocol, &defaultType](Type type) {
// Treat `std.string` as a default type just like we do
// Swift standard library `String`. This helps to disambiguate
// operator overloads that use `std.string` vs. a custom C++
// type that conforms to `ExpressibleByStringLiteral` as well.
//
// This doesn't clash with String because inference won't attempt
// C++ types unless we discover them from a constraint and the
// optimizer and old hacks always prefer the actual default type.
if (literalProtocol->getKnownProtocolKind() ==
KnownProtocolKind::ExpressibleByStringLiteral &&
type->isCxxString()) {
return true;
}
// Check whether the nominal types match. This makes sure that we
// properly handle Array vs. Array<T>.
return defaultType->getAnyNominal() == type->getAnyNominal();
};
if (!isDefaultType(type))
// Check whether the nominal types match. This makes sure that we
// properly handle Array vs. Array<T>.
if (defaultType->getAnyNominal() != type->getAnyNominal()) {
increaseScore(SK_NonDefaultLiteral, locator);
}
}
break;