Skip to content

Commit cd08350

Browse files
committed
[Diagnostics] Prioritize type mismatches over labeling failures for calls
Since labels are considered part of the name, mismatches in labeling should be invalidate overload choices. Let's prefer an overload with correct labels but incorrect types over the one with incorrect labels. This also means that it's possible to restore performance optimizations related to early filtering in diagnostic mode, which is important for deeply nested code i.e. SwiftUI views.
1 parent 0ee9e69 commit cd08350

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9221,13 +9221,6 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
92219221
for (auto *choice : choices.slice(1))
92229222
choice->setDisabled();
92239223
}
9224-
9225-
// Don't attempt further optimization in "diagnostic mode" because
9226-
// in such mode we'd like to attempt all of the available overloads
9227-
// regardless of problems related to missing or extraneous labels
9228-
// and/or arguments.
9229-
if (solverState)
9230-
return false;
92319224
}
92329225

92339226
/// The common result type amongst all function overloads.

test/Constraints/result_builder_diags.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func erroneousSR11350(x: Int) {
249249
if b {
250250
acceptInt(0) { }
251251
}
252-
}).domap(0) // expected-error{{value of type '()?' has no member 'domap'}}
252+
}).domap(0) // expected-error{{value of type 'Optional<()>' has no member 'domap'}}
253253
}
254254
}
255255

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %target-typecheck-verify-swift -target x86_64-apple-macosx10.15 -swift-version 5
2+
// REQUIRES: objc_interop
3+
// REQUIRES: OS=macosx
4+
5+
import SwiftUI
6+
7+
enum E {
8+
case a, b, c
9+
}
10+
11+
struct S : View {
12+
let values: [E] = [.a, .b, .c]
13+
14+
var body: some View {
15+
ScrollView(.vertical) {
16+
Group {
17+
Group {
18+
ForEach(values, id: \.self) { color in
19+
Button(action: { labeled(true) }) { // expected-error {{missing argument label 'value:' in call}} {{38-38=value: }}
20+
Text("").bold()
21+
}.buttonStyle(BorderlessButtonStyle())
22+
}
23+
24+
ForEach([1, 2, 3, 4, 5, 6, 7, 8, 9], id: \.self) { _ in
25+
Button(action: { labeled(value: true) }) {
26+
Text("").bold()
27+
}.buttonStyle(BorderlessButtonStyle())
28+
}
29+
}
30+
.frame(width: 100, height: 100)
31+
.padding(.top, 1)
32+
}
33+
}
34+
.frame(width: 100)
35+
}
36+
37+
func labeled(value: Bool) {}
38+
}

0 commit comments

Comments
 (0)