[Diagnostics] Use argument mismatch fix for @autoclosure result positions

`@autoclosure` is associated with a parameter, we use argument mismatch fix
to diagnose missing explicit calls as well as any mismatches in that position.

Resolves: rdar://110527062
(cherry picked from commit b3e9cf3424)
This commit is contained in:
Pavel Yaskevich
2025-05-26 00:17:08 -07:00
parent 8a51175acb
commit 814b83b9fa
2 changed files with 12 additions and 1 deletions

View File

@@ -4282,7 +4282,8 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
if (!path.empty()) {
auto last = path.back();
if (last.is<LocatorPathElt::ApplyArgToParam>()) {
if (last.is<LocatorPathElt::ApplyArgToParam>() ||
last.is<LocatorPathElt::AutoclosureResult>()) {
auto proto = protoDecl->getDeclaredInterfaceType();
// Impact is 2 here because there are two failures
// 1 - missing conformance and 2 - incorrect argument type.

View File

@@ -1337,3 +1337,13 @@ func rdar143338891() {
}
}
}
do {
struct V {
init(value: @autoclosure @escaping () -> any Hashable) { }
init(other: @autoclosure @escaping () -> String) { }
}
let _ = V(value: { [Int]() }) // expected-error {{add () to forward '@autoclosure' parameter}} {{31-31=()}}
let _ = V(other: { [Int]() }) // expected-error {{cannot convert value of type '[Int]' to closure result type 'String'}}
}