Skip to content

Commit 39a7138

Browse files
committed
[CSSimplify] Prevent missing call fix from recording fixes while matching types
We need to be very careful while matching types to test whether a fix is applicable or not to avoid adding extraneous fixes and failing the path early. This is a temporary workaround, the real fix would be to let `matchTypes` to propagate `TMF_ApplyingFixes` down. Resolves: rdar://154010220 Resolves: #82397 (cherry picked from commit 7ecb1fd)
1 parent 2371e1f commit 39a7138

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5366,6 +5366,11 @@ bool ConstraintSystem::repairFailures(
53665366
matchKind = ConstraintKind::Conversion;
53675367
}
53685368

5369+
// FIXME: There is currently no easy way to avoid attempting
5370+
// fixes, matchTypes do not propagate `TMF_ApplyingFix` flag.
5371+
llvm::SaveAndRestore<ConstraintSystemOptions> options(
5372+
Options, Options - ConstraintSystemFlags::AllowFixes);
5373+
53695374
auto result = matchTypes(resultType, dstType, matchKind,
53705375
TypeMatchFlags::TMF_ApplyingFix, locator);
53715376

test/Constraints/assignment.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,16 @@ class С_56396 {
8888
self.callback = callback // expected-error {{cannot assign value of type '(Self) -> Void' to type '(С_56396) -> Void'}}
8989
}
9090
}
91+
92+
// https://github.com/swiftlang/swift/issues/82397
93+
func testFunctionAssignsWithOptionals(fn: @escaping () -> () -> Void) {
94+
let _: (() -> () -> Void)? = fn
95+
let _: (() -> () -> Void)?? = fn
96+
97+
class Super {}
98+
class Sub: Super {}
99+
100+
let b: () -> () -> Sub = { { return Sub() } }
101+
let _: (() -> () -> Super)? = b
102+
let _: (() -> () -> Super)?? = b
103+
}

0 commit comments

Comments
 (0)