Skip to content

Commit 6a03d77

Browse files
authored
Merge pull request #36267 from xedin/renable-label-filtering-in-diag-mode
[Diagnostics] Prioritize type mismatches over labeling failures for c…
2 parents 84cdeb7 + 39b2ff9 commit 6a03d77

File tree

7 files changed

+47
-18
lines changed

7 files changed

+47
-18
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.

lib/Sema/CSStep.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,6 @@ bool TypeChecker::isDeclRefinementOf(ValueDecl *declA, ValueDecl *declB) {
598598
bool DisjunctionStep::shouldSkip(const DisjunctionChoice &choice) const {
599599
auto &ctx = CS.getASTContext();
600600

601-
// Never skip disjunction choices in diagnostic mode.
602-
if (CS.shouldAttemptFixes())
603-
return false;
604-
605601
auto skip = [&](std::string reason) -> bool {
606602
if (CS.isDebugMode()) {
607603
auto &log = getDebugLogger();
@@ -613,11 +609,14 @@ bool DisjunctionStep::shouldSkip(const DisjunctionChoice &choice) const {
613609
return true;
614610
};
615611

616-
if (choice.isDisabled())
612+
613+
// Skip disabled overloads in the diagnostic mode if they do not have a
614+
// fix attached to them e.g. overloads where labels didn't match up.
615+
if (choice.isDisabled() && !(CS.shouldAttemptFixes() && choice.hasFix()))
617616
return skip("disabled");
618617

619-
// Skip unavailable overloads.
620-
if (choice.isUnavailable())
618+
// Skip unavailable overloads (unless in dignostic mode).
619+
if (choice.isUnavailable() && !CS.shouldAttemptFixes())
621620
return skip("unavailable");
622621

623622
if (ctx.TypeCheckerOpts.DisableConstraintSolverPerformanceHacks)

test/Constraints/generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ let arr = [BottleLayout]()
648648
let layout = BottleLayout(count:1)
649649
let ix = arr.firstIndex(of:layout) // expected-error {{referencing instance method 'firstIndex(of:)' on 'Collection' requires that 'BottleLayout' conform to 'Equatable'}}
650650

651-
let _: () -> UInt8 = { .init("a" as Unicode.Scalar) } // expected-error {{missing argument label 'ascii:' in call}}
651+
let _: () -> UInt8 = { .init("a" as Unicode.Scalar) } // expected-error {{initializer 'init(_:)' requires that 'Unicode.Scalar' conform to 'BinaryInteger'}}
652652

653653
// https://bugs.swift.org/browse/SR-9068
654654
func compare<C: Collection, Key: Hashable, Value: Equatable>(c: C)

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

test/stdlib/UnsafePointerDiagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func unsafeRawBufferPointerConversions(
113113
_ = UnsafeRawBufferPointer(start: rp, count: 1)
114114
_ = UnsafeMutableRawBufferPointer(mrbp)
115115
_ = UnsafeRawBufferPointer(mrbp)
116-
_ = UnsafeMutableRawBufferPointer(rbp) // expected-error {{missing argument label 'mutating:' in call}}
116+
_ = UnsafeMutableRawBufferPointer(rbp) // expected-error {{cannot convert value of type 'UnsafeRawBufferPointer' to expected argument type 'UnsafeMutableRawBufferPointer'}}
117117
_ = UnsafeRawBufferPointer(rbp)
118118
_ = UnsafeMutableRawBufferPointer(mbpi)
119119
_ = UnsafeRawBufferPointer(mbpi)
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+
}

validation-test/Sema/type_checker_crashers_fixed/rdar45470505.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ extension BinaryInteger {
44
init(bytes: [UInt8]) { fatalError() }
55

66
init<S: Sequence>(bytes: S) where S.Iterator.Element == UInt8 {
7-
// expected-note@-1 {{incorrect labels for candidate (have: '(_:)', expected: '(bytes:)')}}
87
self.init(bytes // expected-error {{no exact matches in call to initializer}}
98
// expected-note@-1 {{}}
109

0 commit comments

Comments
 (0)