Skip to content

Commit 814b83b

Browse files
committed
[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 b3e9cf3)
1 parent 8a51175 commit 814b83b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4282,7 +4282,8 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
42824282
if (!path.empty()) {
42834283
auto last = path.back();
42844284

4285-
if (last.is<LocatorPathElt::ApplyArgToParam>()) {
4285+
if (last.is<LocatorPathElt::ApplyArgToParam>() ||
4286+
last.is<LocatorPathElt::AutoclosureResult>()) {
42864287
auto proto = protoDecl->getDeclaredInterfaceType();
42874288
// Impact is 2 here because there are two failures
42884289
// 1 - missing conformance and 2 - incorrect argument type.

test/Constraints/closures.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,3 +1337,13 @@ func rdar143338891() {
13371337
}
13381338
}
13391339
}
1340+
1341+
do {
1342+
struct V {
1343+
init(value: @autoclosure @escaping () -> any Hashable) { }
1344+
init(other: @autoclosure @escaping () -> String) { }
1345+
}
1346+
1347+
let _ = V(value: { [Int]() }) // expected-error {{add () to forward '@autoclosure' parameter}} {{31-31=()}}
1348+
let _ = V(other: { [Int]() }) // expected-error {{cannot convert value of type '[Int]' to closure result type 'String'}}
1349+
}

0 commit comments

Comments
 (0)