Skip to content

Commit e49feab

Browse files
Merge pull request swiftlang#38250 from LucianoPAlmeida/SR-14869-crash-l-value
[SR-14869][Sema] Don't record arg mismatch for function type mismatch at parameter
2 parents ac1ca5e + 5802f2e commit e49feab

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4092,11 +4092,23 @@ bool ConstraintSystem::repairFailures(
40924092
path.pop_back();
40934093
// If this is a contextual mismatch between l-value types e.g.
40944094
// `@lvalue String vs. @lvalue Int`, let's pretend that it's okay.
4095-
if (!path.empty() && path.back().is<LocatorPathElt::ContextualType>()) {
4096-
auto *locator = getConstraintLocator(anchor, path.back());
4097-
conversionsOrFixes.push_back(
4098-
IgnoreContextualType::create(*this, lhs, rhs, locator));
4099-
break;
4095+
if (!path.empty()) {
4096+
if (path.back().is<LocatorPathElt::ContextualType>()) {
4097+
auto *locator = getConstraintLocator(anchor, path.back());
4098+
conversionsOrFixes.push_back(
4099+
IgnoreContextualType::create(*this, lhs, rhs, locator));
4100+
break;
4101+
}
4102+
4103+
// If this is a function type param type mismatch in any position,
4104+
// the mismatch we want to report is for the whole structural type.
4105+
auto last = std::find_if(
4106+
path.rbegin(), path.rend(), [](LocatorPathElt &elt) -> bool {
4107+
return elt.is<LocatorPathElt::FunctionArgument>();
4108+
});
4109+
4110+
if (last != path.rend())
4111+
break;
41004112
}
41014113

41024114
LLVM_FALLTHROUGH;

test/Constraints/function_conversion.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,12 @@ func rdar_59703585() {
8181
cb = swiftCallback
8282
// expected-error@-1 {{cannot assign value of type '(UnsafePointer<Int8>, UnsafeMutableRawPointer?) -> ()' to type 'Fn?' (aka 'Optional<@convention(c) (Optional<UnsafePointer<Int8>>, Optional<UnsafeMutableRawPointer>) -> ()>')}}
8383
}
84+
85+
// SR-14869
86+
var v1: (inout Float) -> ()
87+
v1 = { (_: inout Int) in }
88+
// expected-error@-1{{cannot assign value of type '(inout Int) -> ()' to type '(inout Float) -> ()'}}
89+
90+
var v2: (Int , inout Float) -> ()
91+
v2 = { (_: Int, _: inout Int) in }
92+
// expected-error@-1{{cannot assign value of type '(Int, inout Int) -> ()' to type '(Int, inout Float) -> ()'}}

0 commit comments

Comments
 (0)