checker: check index_expr or_expr types mismatch (#10224)
							parent
							
								
									39de06c200
								
							
						
					
					
						commit
						6e493ca8ca
					
				|  | @ -6522,6 +6522,7 @@ pub fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type { | |||
| 		} | ||||
| 	} | ||||
| 	c.stmts(node.or_expr.stmts) | ||||
| 	c.check_expr_opt_call(node, typ) | ||||
| 	return typ | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,14 @@ | |||
| vlib/v/checker/tests/or_expr_types_mismatch.vv:3:19: error: wrong return type `none` in the `or {}` block, expected `string` | ||||
|     1 | fn get_map() ?string { | ||||
|     2 |     m := map{1: 'a', 2: 'b'} | ||||
|     3 |     return m[1] or { none } | ||||
|       |                      ~~~~ | ||||
|     4 | } | ||||
|     5 | | ||||
| vlib/v/checker/tests/or_expr_types_mismatch.vv:8:19: error: wrong return type `none` in the `or {}` block, expected `int` | ||||
|     6 | fn get_array() ?int { | ||||
|     7 |     a := [1, 2, 3] | ||||
|     8 |     return a[4] or { none } | ||||
|       |                      ~~~~ | ||||
|     9 | } | ||||
|    10 | | ||||
|  | @ -0,0 +1,17 @@ | |||
| fn get_map() ?string { | ||||
| 	m := map{1: 'a', 2: 'b'} | ||||
| 	return m[1] or { none } | ||||
| } | ||||
| 
 | ||||
| fn get_array() ?int { | ||||
| 	a := [1, 2, 3] | ||||
| 	return a[4] or { none } | ||||
| } | ||||
| 
 | ||||
| fn main() { | ||||
| 	map_result := get_map() or { return } | ||||
| 	println(map_result) | ||||
| 
 | ||||
| 	array_result := get_array() or { return } | ||||
| 	println(array_result) | ||||
| } | ||||
		Loading…
	
		Reference in New Issue