Skip to content

Commit 532498b

Browse files
committed
[CSApply] Use the choiceLocator, not locator when checking if a disjunction choice exists
Obviously we won't have a disjunction choice for the locator, it's only possible if the locator is extended with ImplicitlyUnwrappedDisjunctionChoice path element
1 parent a2daa11 commit 532498b

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/Sema/CSApply.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,21 +2269,20 @@ namespace {
22692269
if (!choice.isImplicitlyUnwrappedValueOrReturnValue())
22702270
return false;
22712271

2272-
// If we have an IUO function call and don't have a disjunction choice,
2273-
// then it means we didn't create a disjunction because the call was
2274-
// wrapped in parens (i.e. '(s.returnsAnIUO)()') and so there's no
2275-
// need to force unwrap.
2276-
if (!solution.DisjunctionChoices.count(
2277-
cs.getConstraintLocator(locator))) {
2272+
auto *choiceLocator = cs.getConstraintLocator(locator.withPathElement(
2273+
ConstraintLocator::ImplicitlyUnwrappedDisjunctionChoice));
2274+
2275+
// We won't have a disjunction choice if we have an IUO function call
2276+
// wrapped in parens (i.e. '(s.foo)()'), because we only create a
2277+
// single constraint to bind to an optional type. So, we can just return
2278+
// false here as there's no need to force unwrap.
2279+
if (!solution.DisjunctionChoices.count(choiceLocator)) {
22782280
auto type = choice.getDecl()->getInterfaceType();
22792281
assert((type && type->is<AnyFunctionType>()) &&
22802282
"expected a function type");
22812283
return false;
22822284
}
22832285

2284-
auto *choiceLocator = cs.getConstraintLocator(locator.withPathElement(
2285-
ConstraintLocator::ImplicitlyUnwrappedDisjunctionChoice));
2286-
22872286
return solution.getDisjunctionChoice(choiceLocator);
22882287
}
22892288

0 commit comments

Comments
 (0)