Skip to content

Commit d0ae1d9

Browse files
authored
Merge pull request #24483 from xedin/rdar-50438071
[ConstraintSystem] Tighten "missing call" fix conditions by checking …
2 parents 8c26046 + 0275689 commit d0ae1d9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,8 @@ bool ConstraintSystem::repairFailures(
20322032
// If left-hand side is a function type but right-hand
20332033
// side isn't, let's check it would be possible to fix
20342034
// this by forming an explicit call.
2035-
if (!rhs->is<FunctionType>() && !rhs->isVoid() &&
2035+
auto convertTo = rhs->lookThroughAllOptionalTypes();
2036+
if (!convertTo->is<FunctionType>() && !convertTo->isVoid() &&
20362037
fnType->getNumParams() == 0 &&
20372038
matchTypes(fnType->getResult(), rhs, ConstraintKind::Conversion,
20382039
TypeMatchFlags::TMF_ApplyingFix, locator)

test/Constraints/optional.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,15 @@ func rdar47776586() {
345345
dict[1] += 1 // expected-error {{value of optional type 'Int?' must be unwrapped to a value of type 'Int'}}
346346
// expected-note@-1 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{10-10=!}}
347347
}
348+
349+
struct S {
350+
var foo: Optional<() -> Int?> = nil
351+
var bar: Optional<() -> Int?> = nil
352+
353+
mutating func test(_ clj: @escaping () -> Int) {
354+
if let fn = foo {
355+
bar = fn // Ok
356+
bar = clj // Ok
357+
}
358+
}
359+
}

0 commit comments

Comments
 (0)