Skip to content

[SR-14869][Sema] Don't record arg mismatch for function type mismatch at parameter #38250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4092,11 +4092,23 @@ bool ConstraintSystem::repairFailures(
path.pop_back();
// If this is a contextual mismatch between l-value types e.g.
// `@lvalue String vs. @lvalue Int`, let's pretend that it's okay.
if (!path.empty() && path.back().is<LocatorPathElt::ContextualType>()) {
auto *locator = getConstraintLocator(anchor, path.back());
conversionsOrFixes.push_back(
IgnoreContextualType::create(*this, lhs, rhs, locator));
break;
if (!path.empty()) {
if (path.back().is<LocatorPathElt::ContextualType>()) {
auto *locator = getConstraintLocator(anchor, path.back());
conversionsOrFixes.push_back(
IgnoreContextualType::create(*this, lhs, rhs, locator));
break;
}

// If this is a function type param type mismatch in any position,
// the mismatch we want to report is for the whole structural type.
auto last = std::find_if(
path.rbegin(), path.rend(), [](LocatorPathElt &elt) -> bool {
return elt.is<LocatorPathElt::FunctionArgument>();
});

if (last != path.rend())
break;
}

LLVM_FALLTHROUGH;
Expand Down
9 changes: 9 additions & 0 deletions test/Constraints/function_conversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,12 @@ func rdar_59703585() {
cb = swiftCallback
// expected-error@-1 {{cannot assign value of type '(UnsafePointer<Int8>, UnsafeMutableRawPointer?) -> ()' to type 'Fn?' (aka 'Optional<@convention(c) (Optional<UnsafePointer<Int8>>, Optional<UnsafeMutableRawPointer>) -> ()>')}}
}

// SR-14869
var v1: (inout Float) -> ()
v1 = { (_: inout Int) in }
// expected-error@-1{{cannot assign value of type '(inout Int) -> ()' to type '(inout Float) -> ()'}}

var v2: (Int , inout Float) -> ()
v2 = { (_: Int, _: inout Int) in }
// expected-error@-1{{cannot assign value of type '(Int, inout Int) -> ()' to type '(Int, inout Float) -> ()'}}