Skip to content

Commit e3cd2ab

Browse files
authored
Merge pull request #61778 from xedin/rdar-98862079
[Diagnostics] Diagnose type with mismatching generic arguments in ternary expr
2 parents a252dae + 8ab37ca commit e3cd2ab

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,10 @@ bool GenericArgumentsMismatchFailure::diagnoseAsError() {
794794
} else {
795795
const auto &last = path.back();
796796
switch (last.getKind()) {
797+
case ConstraintLocator::TernaryBranch:
798+
diagnostic = diag::ternary_expr_cases_mismatch;
799+
break;
800+
797801
case ConstraintLocator::ContextualType: {
798802
auto purpose = getContextualTypePurpose();
799803
assert(!(purpose == CTP_Unused || purpose == CTP_CannotFail));
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
2+
// REQUIRES: objc_interop
3+
// REQUIRES: OS=macosx
4+
5+
import SwiftUI
6+
7+
struct NewBounds {
8+
var minBinding: Binding<Double>!
9+
var maxBinding: Binding<Double>!
10+
}
11+
12+
func test<V>(
13+
value: Binding<V>,
14+
in bounds: ClosedRange<V>
15+
) -> some View where V : BinaryFloatingPoint, V.Stride : BinaryFloatingPoint {
16+
EmptyView()
17+
}
18+
19+
struct MyView : View {
20+
@State var newBounds: NewBounds
21+
var bounds: ClosedRange<Double>
22+
23+
var body: some View {
24+
test(value: true ? $newBounds.maxBinding : $newBounds.minBinding, in: bounds)
25+
// expected-error@-1 2 {{result values in '? :' expression have mismatching types 'Binding<Binding<Double>?>' and 'Binding<Double>'}}
26+
// expected-note@-2 2 {{arguments to generic parameter 'Value' ('Binding<Double>?' and 'Double') are expected to be equal}}
27+
}
28+
}

0 commit comments

Comments
 (0)