Merge pull request #71371 from slavapestov/ncgenerics-fixes-3

Non-copyable generics fixes, part 3
This commit is contained in:
Slava Pestov
2024-02-06 08:35:07 -05:00
committed by GitHub
47 changed files with 432 additions and 400 deletions

View File

@@ -3889,19 +3889,21 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
return getTypeMatchAmbiguous();
}
// move-only types (and their metatypes) cannot match with existential types.
if (type1->getMetatypeInstanceType()->isNoncopyable()) {
// tailor error message
if (shouldAttemptFixes()) {
auto *fix = MustBeCopyable::create(*this,
type1,
NoncopyableMatchFailure::forExistentialCast(
type2),
getConstraintLocator(locator));
if (!recordFix(fix))
return getTypeMatchSuccess();
if (!SWIFT_ENABLE_EXPERIMENTAL_NONCOPYABLE_GENERICS) {
// move-only types (and their metatypes) cannot match with existential types.
if (type1->getMetatypeInstanceType()->isNoncopyable()) {
// tailor error message
if (shouldAttemptFixes()) {
auto *fix = MustBeCopyable::create(*this,
type1,
NoncopyableMatchFailure::forExistentialCast(
type2),
getConstraintLocator(locator));
if (!recordFix(fix))
return getTypeMatchSuccess();
}
return getTypeMatchFailure(locator);
}
return getTypeMatchFailure(locator);
}
// FIXME: Feels like a hack.