Sema: Workaround for broken existential opening behavior

This is a narrow workaround for a regression from
9e3d0e0a8c.

There is no reason to skip this logic for protocol extension
members, except that doing so happens to break existential
opening in an expression that involves a call to Array.init
elsewhere.

However there is an underlying issue here with existential opening,
which doesn't seem to work right in the presence of overloading.

The test case demonstrates the fixed problem, together with an
existing bug that points to the underlying problem.

Fixes rdar://160389221.
This commit is contained in:
Slava Pestov
2025-09-24 17:58:22 -04:00
parent 8f7af45115
commit 40948d7abd
2 changed files with 35 additions and 1 deletions

View File

@@ -13394,8 +13394,12 @@ retry_after_fail:
choiceType = objectType;
}
// FIXME: The !getSelfProtocolDecl() check is load-bearing, because
// this optimization interacts poorly with existential opening
// somehow. It should all be removed.
if (auto *choiceFnType = choiceType->getAs<FunctionType>()) {
if (isa<ConstructorDecl>(choice.getDecl())) {
if (isa<ConstructorDecl>(choice.getDecl()) &&
!choice.getDecl()->getDeclContext()->getSelfProtocolDecl()) {
auto choiceResultType = choice.getBaseType()
->getRValueType()
->getMetatypeInstanceType();