[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.
This commit is contained in:
Hamish Knight
2024-12-29 12:25:18 +00:00
parent 2c2038d459
commit 86e8165569
3 changed files with 18 additions and 11 deletions

View File

@@ -3903,14 +3903,6 @@ bool MissingCallFailure::diagnoseAsError() {
return true;
}
case ConstraintLocator::FunctionResult: {
path = path.drop_back();
if (path.back().getKind() != ConstraintLocator::AutoclosureResult)
break;
LLVM_FALLTHROUGH;
}
case ConstraintLocator::AutoclosureResult: {
auto loc = getConstraintLocator(getRawAnchor(), path.drop_back());
AutoClosureForwardingFailure failure(getSolution(), loc);

View File

@@ -3389,8 +3389,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
continue;
}
case ConstraintLocator::ApplyFunction:
case ConstraintLocator::FunctionResult:
case ConstraintLocator::ApplyFunction: {
// Extract application function.
if (auto applyExpr = getAsExpr<ApplyExpr>(anchor)) {
anchor = applyExpr->getFn();
@@ -3412,7 +3411,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
}
break;
}
case ConstraintLocator::AutoclosureResult:
case ConstraintLocator::LValueConversion:
case ConstraintLocator::DynamicType:
@@ -3677,6 +3676,7 @@ void constraints::simplifyLocator(ASTNode &anchor,
case ConstraintLocator::SynthesizedArgument:
break;
case ConstraintLocator::FunctionResult:
case ConstraintLocator::DynamicLookupResult:
case ConstraintLocator::KeyPathComponentResult:
break;

View File

@@ -0,0 +1,15 @@
// RUN: %target-typecheck-verify-swift %clang-importer-sdk
// REQUIRES: objc_interop
import Foundation
import CoreGraphics
func foo(_ x: Double) {}
func bar() -> Double { 0 }
// https://github.com/swiftlang/swift/issues/78376
let _: (CGFloat) -> Void = foo
// expected-error@-1 {{cannot convert value of type '(Double) -> ()' to specified type '(CGFloat) -> Void'}}
let _: () -> CGFloat = bar
// expected-error@-1 {{cannot convert value of type '() -> Double' to specified type '() -> CGFloat'}}