Commit db8c752 1 parent d022e0e commit db8c752 Copy full SHA for db8c752
File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ impl<'a> InferenceContext<'a> {
85
85
let ty = match & self . body [ tgt_expr] {
86
86
Expr :: Missing => self . err_ty ( ) ,
87
87
& Expr :: If { condition, then_branch, else_branch } => {
88
+ let expected = & expected. adjust_for_branches ( & mut self . table ) ;
88
89
self . infer_expr (
89
90
condition,
90
91
& Expectation :: has_type ( TyKind :: Scalar ( Scalar :: Bool ) . intern ( Interner ) ) ,
Original file line number Diff line number Diff line change @@ -122,6 +122,23 @@ fn test() {
122
122
)
123
123
}
124
124
125
+ #[ test]
126
+ fn if_else_adjust_for_branches_discard_type_var ( ) {
127
+ check_no_mismatches (
128
+ r#"
129
+ fn test() {
130
+ let f = || {
131
+ if true {
132
+ &""
133
+ } else {
134
+ ""
135
+ }
136
+ };
137
+ }
138
+ "# ,
139
+ ) ;
140
+ }
141
+
125
142
#[ test]
126
143
fn match_first_coerce ( ) {
127
144
check_no_mismatches (
@@ -182,6 +199,22 @@ fn test() {
182
199
) ;
183
200
}
184
201
202
+ #[ test]
203
+ fn match_adjust_for_branches_discard_type_var ( ) {
204
+ check_no_mismatches (
205
+ r#"
206
+ fn test() {
207
+ let f = || {
208
+ match 0i32 {
209
+ 0i32 => &"",
210
+ _ => "",
211
+ }
212
+ };
213
+ }
214
+ "# ,
215
+ ) ;
216
+ }
217
+
185
218
#[ test]
186
219
fn return_coerce_unknown ( ) {
187
220
check_types (
You can’t perform that action at this time.
0 commit comments