Skip to content

Commit 6eeb6f9

Browse files
authored
Merge pull request #76470 from xedin/rdar-135974645
[CSSimplify] Forego any contextual score increases while checking era…
2 parents 586ac09 + 0276a33 commit 6eeb6f9

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

include/swift/Sema/ConstraintLocator.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,21 @@ class ConstraintLocatorBuilder {
12811281
return false;
12821282
}
12831283

1284+
bool isForExistentialMemberAccessConversion() const {
1285+
for (auto prev = this; prev;
1286+
prev = prev->previous.dyn_cast<ConstraintLocatorBuilder *>()) {
1287+
if (auto elt = prev->element) {
1288+
if (elt->is<LocatorPathElt::ExistentialMemberAccessConversion>())
1289+
return true;
1290+
}
1291+
1292+
if (auto locator = prev->previous.dyn_cast<ConstraintLocator *>())
1293+
return bool(locator->findLast<
1294+
LocatorPathElt::ExistentialMemberAccessConversion>());
1295+
}
1296+
return false;
1297+
}
1298+
12841299
std::optional<std::pair</*witness=*/ValueDecl *, GenericTypeParamType *>>
12851300
isForWitnessGenericParameterRequirement() const {
12861301
SmallVector<LocatorPathElt, 2> path;

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14083,6 +14083,12 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
1408314083
// This induces conversions to occur within closures instead of
1408414084
// outside of them wherever possible.
1408514085
if (locator.isFunctionConversion()) {
14086+
// This conversion exists only to check adjustments in the member
14087+
// type, so the fact that adjustments also cause a function conversion
14088+
// is unrelated.
14089+
if (locator.isForExistentialMemberAccessConversion())
14090+
return;
14091+
1408614092
increaseScore(SK_FunctionConversion, locator);
1408714093
}
1408814094
};

test/decl/protocol/existential_member_accesses_self_assoctype.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,4 +1062,11 @@ protocol PackExpansionResult {
10621062
func packExpansionResult(p: any PackExpansionResult) {
10631063
p.foo(t: 1, "hi")
10641064
// expected-error@-1 {{member 'foo' cannot be used on value of type 'any PackExpansionResult'; consider using a generic constraint instead}}
1065-
}
1065+
}
1066+
1067+
// rdar://135974645 - invalid error: heterogeneous collection literal could only be inferred to '[Any]'
1068+
extension StringProtocol {
1069+
func test(target: any StringProtocol, idx: Int) {
1070+
let _ = [target.prefix(idx), target.suffix(idx)] // Ok
1071+
}
1072+
}

0 commit comments

Comments
 (0)