checker: modify error messages for ptrs (#6325)
parent
3f7970db52
commit
ea2b2ebc07
|
@ -580,18 +580,24 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
|
|||
if left.has_method(infix_expr.op.str()) {
|
||||
return_type = left_type
|
||||
} else {
|
||||
c.error('mismatched types `$left.name` and `$right.name`', left_pos)
|
||||
left_name := c.table.type_to_str(left_type)
|
||||
right_name := c.table.type_to_str(right_type)
|
||||
c.error('mismatched types `$left_name` and `$right_name`', left_pos)
|
||||
}
|
||||
} else if right.kind in [.array, .array_fixed, .map, .struct_] {
|
||||
if right.has_method(infix_expr.op.str()) {
|
||||
return_type = right_type
|
||||
} else {
|
||||
c.error('mismatched types `$left.name` and `$right.name`', right_pos)
|
||||
left_name := c.table.type_to_str(left_type)
|
||||
right_name := c.table.type_to_str(right_type)
|
||||
c.error('mismatched types `$left_name` and `$right_name`', right_pos)
|
||||
}
|
||||
} else {
|
||||
promoted_type := c.promote(c.table.unalias_num_type(left_type), c.table.unalias_num_type(right_type))
|
||||
if promoted_type.idx() == table.void_type_idx {
|
||||
c.error('mismatched types `$left.name` and `$right.name`', infix_expr.pos)
|
||||
left_name := c.table.type_to_str(left_type)
|
||||
right_name := c.table.type_to_str(right_type)
|
||||
c.error('mismatched types `$left_name` and `$right_name`', infix_expr.pos)
|
||||
} else if promoted_type.is_float() {
|
||||
if infix_expr.op in [.mod, .xor, .amp, .pipe] {
|
||||
side := if left_type == promoted_type { 'left' } else { 'right' }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/add_op_wrong_left_type_err_c.vv:3:13: error: mismatched types `map_string_int` and `any_int`
|
||||
vlib/v/checker/tests/add_op_wrong_left_type_err_c.vv:3:13: error: mismatched types `map[string]int` and `any_int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(a + 10)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/add_op_wrong_right_type_err_c.vv:3:18: error: mismatched types `any_int` and `map_string_int`
|
||||
vlib/v/checker/tests/add_op_wrong_right_type_err_c.vv:3:18: error: mismatched types `any_int` and `map[string]int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(10 + a)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/div_op_wrong_left_type_err_c.vv:3:13: error: mismatched types `map_string_int` and `any_int`
|
||||
vlib/v/checker/tests/div_op_wrong_left_type_err_c.vv:3:13: error: mismatched types `map[string]int` and `any_int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(a / 10)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/div_op_wrong_right_type_err_c.vv:3:18: error: mismatched types `any_int` and `map_string_int`
|
||||
vlib/v/checker/tests/div_op_wrong_right_type_err_c.vv:3:18: error: mismatched types `any_int` and `map[string]int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(10 / a)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/minus_op_wrong_left_type_err_c.vv:3:13: error: mismatched types `map_string_int` and `any_int`
|
||||
vlib/v/checker/tests/minus_op_wrong_left_type_err_c.vv:3:13: error: mismatched types `map[string]int` and `any_int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(a - 10)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/minus_op_wrong_right_type_err_c.vv:3:18: error: mismatched types `any_int` and `map_string_int`
|
||||
vlib/v/checker/tests/minus_op_wrong_right_type_err_c.vv:3:18: error: mismatched types `any_int` and `map[string]int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(10 - a)
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
vlib/v/checker/tests/mismatched_ptr_op_ptr.vv:5:18: error: mismatched types `&string` and `string`
|
||||
3 | unsafe {
|
||||
4 | b := &a
|
||||
5 | println(b+*b)
|
||||
| ^
|
||||
6 | println(b+b)
|
||||
7 | }
|
||||
vlib/v/checker/tests/mismatched_ptr_op_ptr.vv:6:18: error: mismatched types `&string` and `&string`
|
||||
4 | b := &a
|
||||
5 | println(b+*b)
|
||||
6 | println(b+b)
|
||||
| ^
|
||||
7 | }
|
||||
8 | }
|
|
@ -0,0 +1,8 @@
|
|||
fn main() {
|
||||
a := '1'
|
||||
unsafe {
|
||||
b := &a
|
||||
println(b+*b)
|
||||
println(b+b)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/mod_op_wrong_left_type_err_d.vv:3:10: error: mismatched types `map_string_int` and `any_int`
|
||||
vlib/v/checker/tests/mod_op_wrong_left_type_err_d.vv:3:10: error: mismatched types `map[string]int` and `any_int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(a % 1)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/mod_op_wrong_right_type_err_d.vv:3:14: error: mismatched types `any_int` and `map_string_int`
|
||||
vlib/v/checker/tests/mod_op_wrong_right_type_err_d.vv:3:14: error: mismatched types `any_int` and `map[string]int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(1 % a)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/mul_op_wrong_left_type_err_c.vv:3:13: error: mismatched types `map_string_int` and `any_int`
|
||||
vlib/v/checker/tests/mul_op_wrong_left_type_err_c.vv:3:13: error: mismatched types `map[string]int` and `any_int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(a * 10)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/mul_op_wrong_right_type_err_c.vv:3:18: error: mismatched types `any_int` and `map_string_int`
|
||||
vlib/v/checker/tests/mul_op_wrong_right_type_err_c.vv:3:18: error: mismatched types `any_int` and `map[string]int`
|
||||
1 | fn main() {
|
||||
2 | a := map[string]int
|
||||
3 | println(10 * a)
|
||||
|
|
Loading…
Reference in New Issue