File tree Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -729,7 +729,7 @@ impl<'a> InferenceContext<'a> {
729
729
TyKind :: Tuple ( tys. len ( ) , Substitution :: from_iter ( & Interner , tys) ) . intern ( & Interner )
730
730
}
731
731
Expr :: Array ( array) => {
732
- let elem_ty =
732
+ let mut elem_ty =
733
733
match expected. to_option ( & mut self . table ) . as_ref ( ) . map ( |t| t. kind ( & Interner ) ) {
734
734
Some ( TyKind :: Array ( st, _) | TyKind :: Slice ( st) ) => st. clone ( ) ,
735
735
_ => self . table . new_type_var ( ) ,
@@ -738,8 +738,8 @@ impl<'a> InferenceContext<'a> {
738
738
let len = match array {
739
739
Array :: ElementList ( items) => {
740
740
for expr in items. iter ( ) {
741
- // FIXME: use CoerceMany (coerce_merge_branch)
742
- self . infer_expr_coerce ( * expr, & Expectation :: has_type ( elem_ty. clone ( ) ) ) ;
741
+ let cur_elem_ty = self . infer_expr_inner ( * expr , expected ) ;
742
+ elem_ty = self . coerce_merge_branch ( Some ( * expr) , & elem_ty, & cur_elem_ty ) ;
743
743
}
744
744
Some ( items. len ( ) as u64 )
745
745
}
Original file line number Diff line number Diff line change @@ -507,3 +507,17 @@ fn main() {
507
507
"# ,
508
508
) ;
509
509
}
510
+
511
+ #[ test]
512
+ fn coerce_array_elems_lub ( ) {
513
+ check_no_mismatches (
514
+ r#"
515
+ fn f() {}
516
+ fn g() {}
517
+
518
+ fn test() {
519
+ [f, g];
520
+ }
521
+ "# ,
522
+ ) ;
523
+ }
Original file line number Diff line number Diff line change @@ -117,19 +117,19 @@ fn recursive_vars_2() {
117
117
"# ,
118
118
expect ! [ [ r#"
119
119
10..79 '{ ...x)]; }': ()
120
- 20..21 'x': & {unknown}
121
- 24..31 'unknown': & {unknown}
120
+ 20..21 'x': {unknown}
121
+ 24..31 'unknown': {unknown}
122
122
41..42 'y': {unknown}
123
123
45..52 'unknown': {unknown}
124
- 58..76 '[(x, y..., &x)]': [(& {unknown}, {unknown}); 2]
125
- 59..65 '(x, y)': (& {unknown}, {unknown})
126
- 60..61 'x': & {unknown}
124
+ 58..76 '[(x, y..., &x)]': [({unknown}, {unknown}); 2]
125
+ 59..65 '(x, y)': ({unknown}, {unknown})
126
+ 60..61 'x': {unknown}
127
127
63..64 'y': {unknown}
128
- 67..75 '(&y, &x)': (&{unknown}, {unknown})
128
+ 67..75 '(&y, &x)': (&{unknown}, & {unknown})
129
129
68..70 '&y': &{unknown}
130
130
69..70 'y': {unknown}
131
- 72..74 '&x': && {unknown}
132
- 73..74 'x': & {unknown}
131
+ 72..74 '&x': &{unknown}
132
+ 73..74 'x': {unknown}
133
133
"# ] ] ,
134
134
) ;
135
135
}
You can’t perform that action at this time.
0 commit comments