Skip to content

Commit a7ac64a

Browse files
committed
[CSOptimizer] Restrict unary argument legacy favoring behavior to ApplyExprs
The original hack never applied to subscripts.
1 parent 9dda7d5 commit a7ac64a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,10 @@ static std::optional<DisjunctionInfo> preserveFavoringOfUnlabeledUnaryArgument(
581581
if (!argumentList->isUnlabeledUnary())
582582
return std::nullopt;
583583

584+
if (!isExpr<ApplyExpr>(
585+
cs.getParentExpr(argumentList->getUnlabeledUnaryExpr())))
586+
return std::nullopt;
587+
584588
auto ODRE = isOverloadedDeclRef(disjunction);
585589
bool preserveFavoringOfUnlabeledUnaryArgument =
586590
!ODRE || numOverloadChoicesMatchingOnArity(ODRE, argumentList) < 2;

test/Constraints/old_hack_related_ambiguities.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,21 @@ func test_variadic_static_member_is_preferred_over_partially_applied_instance_ov
272272
let t: Test
273273
Test.fn(t) // Ok
274274
}
275+
276+
// Unary unlabeled argument favoring hacks never applied to subscripts
277+
278+
protocol Subscriptable {
279+
}
280+
281+
extension Subscriptable {
282+
subscript(key: String) -> Any? { nil }
283+
}
284+
285+
struct MyValue {}
286+
287+
extension Dictionary<String, MyValue> : Subscriptable {}
288+
289+
func test_that_unary_argument_hacks_do_not_apply_to_subscripts(dict: [String: MyValue]) {
290+
let value = dict["hello"]
291+
let _: MyValue? = value // Ok
292+
}

0 commit comments

Comments
 (0)