diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index fa8b19072360d..2550170bb7cad 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -5365,6 +5365,11 @@ bool ConstraintSystem::repairFailures( matchKind = ConstraintKind::Conversion; } + // FIXME: There is currently no easy way to avoid attempting + // fixes, matchTypes do not propagate `TMF_ApplyingFix` flag. + llvm::SaveAndRestore options( + Options, Options - ConstraintSystemFlags::AllowFixes); + auto result = matchTypes(resultType, dstType, matchKind, TypeMatchFlags::TMF_ApplyingFix, locator); diff --git a/test/Constraints/assignment.swift b/test/Constraints/assignment.swift index 4ccdf8951bee3..f97b7e4c25031 100644 --- a/test/Constraints/assignment.swift +++ b/test/Constraints/assignment.swift @@ -88,3 +88,16 @@ class С_56396 { self.callback = callback // expected-error {{cannot assign value of type '(Self) -> Void' to type '(С_56396) -> Void'}} } } + +// https://github.com/swiftlang/swift/issues/82397 +func testFunctionAssignsWithOptionals(fn: @escaping () -> () -> Void) { + let _: (() -> () -> Void)? = fn + let _: (() -> () -> Void)?? = fn + + class Super {} + class Sub: Super {} + + let b: () -> () -> Sub = { { return Sub() } } + let _: (() -> () -> Super)? = b + let _: (() -> () -> Super)?? = b +}