Skip to content

Commit 5053e8a

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
1 parent 857ed26 commit 5053e8a

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
@@ -5365,6 +5365,11 @@ bool ConstraintSystem::repairFailures(
53655365
matchKind = ConstraintKind::Conversion;
53665366
}
53675367

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

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)