Skip to content

Commit 28d0c08

Browse files
committed
[CSApply] shouldForceUnwrapResult() should return false when we don't have an disjunction choice
This will only be false if we have an IUO method call wrapped in parens (like '(s.foo)()'), so assert that the type is a function type as well
1 parent 32cfd5b commit 28d0c08

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,6 +2266,18 @@ namespace {
22662266
if (!choice.isImplicitlyUnwrappedValueOrReturnValue())
22672267
return false;
22682268

2269+
// If we have an IUO function call and don't have a disjunction choice,
2270+
// then it means we didn't create a disjunction because the call was
2271+
// wrapped in parens (i.e. '(s.returnsAnIUO)()') and so there's no
2272+
// need to force unwrap.
2273+
if (!solution.DisjunctionChoices.count(
2274+
cs.getConstraintLocator(locator))) {
2275+
auto type = choice.getDecl()->getInterfaceType();
2276+
assert((type && type->is<AnyFunctionType>()) &&
2277+
"expected a function type");
2278+
return false;
2279+
}
2280+
22692281
auto *choiceLocator = cs.getConstraintLocator(locator.withPathElement(
22702282
ConstraintLocator::ImplicitlyUnwrappedDisjunctionChoice));
22712283

0 commit comments

Comments
 (0)