Skip to content

Commit 86e8165

Browse files
committed
[CS] Don't simplify FunctionResult in simplifyLocator
Simplifying into the function expression is wrong, like `FunctionArgument` this isn't an element that can be simplified. This also means we don't need to handle it in `MissingCallFailure`, since we shouldn't be recording that fix in this case.
1 parent 2c2038d commit 86e8165

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,14 +3903,6 @@ bool MissingCallFailure::diagnoseAsError() {
39033903
return true;
39043904
}
39053905

3906-
case ConstraintLocator::FunctionResult: {
3907-
path = path.drop_back();
3908-
if (path.back().getKind() != ConstraintLocator::AutoclosureResult)
3909-
break;
3910-
3911-
LLVM_FALLTHROUGH;
3912-
}
3913-
39143906
case ConstraintLocator::AutoclosureResult: {
39153907
auto loc = getConstraintLocator(getRawAnchor(), path.drop_back());
39163908
AutoClosureForwardingFailure failure(getSolution(), loc);

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3389,8 +3389,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
33893389
continue;
33903390
}
33913391

3392-
case ConstraintLocator::ApplyFunction:
3393-
case ConstraintLocator::FunctionResult:
3392+
case ConstraintLocator::ApplyFunction: {
33943393
// Extract application function.
33953394
if (auto applyExpr = getAsExpr<ApplyExpr>(anchor)) {
33963395
anchor = applyExpr->getFn();
@@ -3412,7 +3411,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
34123411
}
34133412

34143413
break;
3415-
3414+
}
34163415
case ConstraintLocator::AutoclosureResult:
34173416
case ConstraintLocator::LValueConversion:
34183417
case ConstraintLocator::DynamicType:
@@ -3677,6 +3676,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
36773676
case ConstraintLocator::SynthesizedArgument:
36783677
break;
36793678

3679+
case ConstraintLocator::FunctionResult:
36803680
case ConstraintLocator::DynamicLookupResult:
36813681
case ConstraintLocator::KeyPathComponentResult:
36823682
break;

test/Constraints/issue-78376.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-typecheck-verify-swift %clang-importer-sdk
2+
3+
// REQUIRES: objc_interop
4+
5+
import Foundation
6+
import CoreGraphics
7+
8+
func foo(_ x: Double) {}
9+
func bar() -> Double { 0 }
10+
11+
// https://github.com/swiftlang/swift/issues/78376
12+
let _: (CGFloat) -> Void = foo
13+
// expected-error@-1 {{cannot convert value of type '(Double) -> ()' to specified type '(CGFloat) -> Void'}}
14+
let _: () -> CGFloat = bar
15+
// expected-error@-1 {{cannot convert value of type '() -> Double' to specified type '() -> CGFloat'}}

0 commit comments

Comments
 (0)