checker: improve error position of infix expr (#8828)

pull/8833/head
zakuro 2021-02-19 19:38:41 +09:00 committed by GitHub
parent ad162cd6fc
commit 6e262b5d84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 160 additions and 147 deletions

View File

@ -700,6 +700,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
left_final := c.table.get_final_type_symbol(left_type)
left_pos := infix_expr.left.position()
right_pos := infix_expr.right.position()
left_right_pos := left_pos.extend(right_pos)
if (left_type.is_ptr() || left.is_pointer()) && infix_expr.op in [.plus, .minus] {
if !c.inside_unsafe && !infix_expr.left.is_mut_ident() && !infix_expr.right.is_mut_ident() {
c.warn('pointer arithmetic is only allowed in `unsafe` blocks', left_pos)
@ -730,7 +731,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
|| (right.kind == .alias && left.kind in [.struct_, .array])
if is_mismatch {
c.error('possible type mismatch of compared values of `$infix_expr.op` operation',
infix_expr.pos)
left_right_pos)
}
}
.key_in, .not_in {
@ -740,20 +741,20 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
// if left_default.kind != right_sym.kind {
c.check_expected(left_type, elem_type) or {
c.error('left operand to `$infix_expr.op` does not match the array element type: $err',
infix_expr.pos)
left_right_pos)
}
}
.map {
elem_type := right.map_info().key_type
c.check_expected(left_type, elem_type) or {
c.error('left operand to `$infix_expr.op` does not match the map key type: $err',
infix_expr.pos)
left_right_pos)
}
}
.string {
c.check_expected(left_type, right_type) or {
c.error('left operand to `$infix_expr.op` does not match: $err',
infix_expr.pos)
left_right_pos)
}
}
else {
@ -784,9 +785,9 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
right_name := c.table.type_to_str(right_type)
if left_name == right_name {
c.error('undefined operation `$left_name` $infix_expr.op.str() `$right_name`',
left_pos)
left_right_pos)
} else {
c.error('mismatched types `$left_name` and `$right_name`', left_pos)
c.error('mismatched types `$left_name` and `$right_name`', left_right_pos)
}
}
} else if right.kind in [.array, .array_fixed, .map, .struct_] {
@ -801,9 +802,9 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
right_name := c.table.type_to_str(right_type)
if left_name == right_name {
c.error('undefined operation `$left_name` $infix_expr.op.str() `$right_name`',
right_pos)
left_right_pos)
} else {
c.error('mismatched types `$left_name` and `$right_name`', right_pos)
c.error('mismatched types `$left_name` and `$right_name`', left_right_pos)
}
}
} else {
@ -811,7 +812,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
if promoted_type.idx() == table.void_type_idx {
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)
c.error('mismatched types `$left_name` and `$right_name`', left_right_pos)
} else if promoted_type.has_flag(.optional) {
s := c.table.type_to_str(promoted_type)
c.error('`$infix_expr.op` cannot be used with `$s`', infix_expr.pos)
@ -844,18 +845,18 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
right_name := c.table.type_to_str(right_type)
if left_name == right_name {
c.error('undefined operation `$left_name` $infix_expr.op.str() `$right_name`',
infix_expr.pos)
left_right_pos)
} else {
c.error('mismatched types `$left_name` and `$right_name`', infix_expr.pos)
c.error('mismatched types `$left_name` and `$right_name`', left_right_pos)
}
}
}
if left.kind == .struct_ && right.kind == .struct_ {
if !left.has_method('<') && infix_expr.op in [.ge, .le] {
c.error('cannot use `$infix_expr.op` as `<` operator method is not defined',
infix_expr.pos)
left_right_pos)
} else if !left.has_method('<') && infix_expr.op == .gt {
c.error('cannot use `>` as `<=` operator method is not defined', infix_expr.pos)
c.error('cannot use `>` as `<=` operator method is not defined', left_right_pos)
}
}
}
@ -972,7 +973,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
left_is_optional := left_type.has_flag(.optional)
right_is_optional := right_type.has_flag(.optional)
if (left_is_optional && !right_is_optional) || (!left_is_optional && right_is_optional) {
c.error('unwrapped optional cannot be used in an infix expression', infix_expr.pos)
c.error('unwrapped optional cannot be used in an infix expression', left_right_pos)
}
// Dual sides check (compatibility check)
if !c.symmetric_check(right_type, left_type) && !c.pref.translated {
@ -981,7 +982,7 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
return table.void_type
}
c.error('infix expr: cannot use `$right.name` (right expression) as `$left.name`',
infix_expr.pos)
left_right_pos)
}
/*
if (infix_expr.left is ast.InfixExpr &&

View File

@ -2,40 +2,41 @@ vlib/v/checker/tests/add_op_wrong_type_err.vv:3:13: error: mismatched types `Aaa
1 | struct Aaa{}
2 | fn main() {
3 | println(Aaa{} + 10)
| ~~~~~
| ~~~~~~~~~~
4 | println(10 + Aaa{})
5 | println([1,2,3] + 10)
vlib/v/checker/tests/add_op_wrong_type_err.vv:4:18: error: mismatched types `int literal` and `Aaa`
vlib/v/checker/tests/add_op_wrong_type_err.vv:4:13: error: mismatched types `int literal` and `Aaa`
2 | fn main() {
3 | println(Aaa{} + 10)
4 | println(10 + Aaa{})
| ~~~~~
| ~~~~~~~~~~
5 | println([1,2,3] + 10)
6 | println(10 + [1,2,3])
vlib/v/checker/tests/add_op_wrong_type_err.vv:5:13: error: mismatched types `[]int` and `int literal`
3 | println(Aaa{} + 10)
4 | println(10 + Aaa{})
5 | println([1,2,3] + 10)
| ~~~~~~~
| ~~~~~~~~~~~~
6 | println(10 + [1,2,3])
7 | a := map[string]int
vlib/v/checker/tests/add_op_wrong_type_err.vv:6:18: error: mismatched types `int literal` and `[]int`
vlib/v/checker/tests/add_op_wrong_type_err.vv:6:13: error: mismatched types `int literal` and `[]int`
4 | println(10 + Aaa{})
5 | println([1,2,3] + 10)
6 | println(10 + [1,2,3])
| ~~~~~~~
| ~~~~~~~~~~~~
7 | a := map[string]int
8 | println(a + 10)
vlib/v/checker/tests/add_op_wrong_type_err.vv:8:13: error: mismatched types `map[string]int` and `int literal`
6 | println(10 + [1,2,3])
7 | a := map[string]int
8 | println(a + 10)
| ^
| ~~~~~~
9 | println(10 + a)
10 | }
vlib/v/checker/tests/add_op_wrong_type_err.vv:9:18: error: mismatched types `int literal` and `map[string]int`
vlib/v/checker/tests/add_op_wrong_type_err.vv:9:13: error: mismatched types `int literal` and `map[string]int`
7 | a := map[string]int
8 | println(a + 10)
9 | println(10 + a)
| ^
| ~~~~~~
10 | }

View File

@ -1,7 +1,8 @@
vlib/v/checker/tests/comparing_typesymbol_to_a_type_should_not_compile.vv:12:12: error: possible type mismatch of compared values of `==` operation
vlib/v/checker/tests/comparing_typesymbol_to_a_type_should_not_compile.vv:12:7: error: possible type mismatch of compared values of `==` operation
10 | x := ityp == table.string_type
11 | // the next line should produce at least a warning, or even an error, without an explicit cast:
12 | z := isym == table.string_type
| ~~
| ~~~~~~~~~~~~~~~~~~~~~~~~~
13 | println(typeof(isym).name)
14 | println(typeof(table.string_type).name)

View File

@ -2,40 +2,41 @@ vlib/v/checker/tests/div_op_wrong_type_err.vv:3:13: error: mismatched types `Aaa
1 | struct Aaa{}
2 | fn main() {
3 | println(Aaa{} / 10)
| ~~~~~
| ~~~~~~~~~~
4 | println(10 / Aaa{})
5 | println([1,2,3] / 10)
vlib/v/checker/tests/div_op_wrong_type_err.vv:4:18: error: mismatched types `int literal` and `Aaa`
vlib/v/checker/tests/div_op_wrong_type_err.vv:4:13: error: mismatched types `int literal` and `Aaa`
2 | fn main() {
3 | println(Aaa{} / 10)
4 | println(10 / Aaa{})
| ~~~~~
| ~~~~~~~~~~
5 | println([1,2,3] / 10)
6 | println(10 / [1,2,3])
vlib/v/checker/tests/div_op_wrong_type_err.vv:5:13: error: mismatched types `[]int` and `int literal`
3 | println(Aaa{} / 10)
4 | println(10 / Aaa{})
5 | println([1,2,3] / 10)
| ~~~~~~~
| ~~~~~~~~~~~~
6 | println(10 / [1,2,3])
7 | a := map[string]int
vlib/v/checker/tests/div_op_wrong_type_err.vv:6:18: error: mismatched types `int literal` and `[]int`
vlib/v/checker/tests/div_op_wrong_type_err.vv:6:13: error: mismatched types `int literal` and `[]int`
4 | println(10 / Aaa{})
5 | println([1,2,3] / 10)
6 | println(10 / [1,2,3])
| ~~~~~~~
| ~~~~~~~~~~~~
7 | a := map[string]int
8 | println(a / 10)
vlib/v/checker/tests/div_op_wrong_type_err.vv:8:13: error: mismatched types `map[string]int` and `int literal`
6 | println(10 / [1,2,3])
7 | a := map[string]int
8 | println(a / 10)
| ^
| ~~~~~~
9 | println(10 / a)
10 | }
vlib/v/checker/tests/div_op_wrong_type_err.vv:9:18: error: mismatched types `int literal` and `map[string]int`
vlib/v/checker/tests/div_op_wrong_type_err.vv:9:13: error: mismatched types `int literal` and `map[string]int`
7 | a := map[string]int
8 | println(a / 10)
9 | println(10 / a)
| ^
| ~~~~~~
10 | }

View File

@ -1,83 +1,84 @@
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:10:16: error: infix expr: cannot use `int literal` (right expression) as `Aaa`
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:10:10: error: infix expr: cannot use `int literal` (right expression) as `Aaa`
8 |
9 | fn main() {
10 | println(Aaa{} == 10)
| ~~
| ~~~~~~~~~~~
11 | println(10 == Aaa{})
12 | println(Aaa{} != 10)
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:11:13: error: infix expr: cannot use `Aaa` (right expression) as `int literal`
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:11:10: error: infix expr: cannot use `Aaa` (right expression) as `int literal`
9 | fn main() {
10 | println(Aaa{} == 10)
11 | println(10 == Aaa{})
| ~~
| ~~~~~~~~~~~
12 | println(Aaa{} != 10)
13 | println(10 != Aaa{})
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:12:16: error: infix expr: cannot use `int literal` (right expression) as `Aaa`
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:12:10: error: infix expr: cannot use `int literal` (right expression) as `Aaa`
10 | println(Aaa{} == 10)
11 | println(10 == Aaa{})
12 | println(Aaa{} != 10)
| ~~
| ~~~~~~~~~~~
13 | println(10 != Aaa{})
14 |
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:13:13: error: infix expr: cannot use `Aaa` (right expression) as `int literal`
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:13:10: error: infix expr: cannot use `Aaa` (right expression) as `int literal`
11 | println(10 == Aaa{})
12 | println(Aaa{} != 10)
13 | println(10 != Aaa{})
| ~~
| ~~~~~~~~~~~
14 |
15 | println(Aaa{0} == AAaa{0})
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:15:17: error: possible type mismatch of compared values of `==` operation
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:15:10: error: possible type mismatch of compared values of `==` operation
13 | println(10 != Aaa{})
14 |
15 | println(Aaa{0} == AAaa{0})
| ~~
| ~~~~~~~~~~~~~~~~~
16 | println(AAaa{0} == Aaa{0})
17 | println(AAaa{1} != Aaa{1})
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:16:18: error: possible type mismatch of compared values of `==` operation
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:16:10: error: possible type mismatch of compared values of `==` operation
14 |
15 | println(Aaa{0} == AAaa{0})
16 | println(AAaa{0} == Aaa{0})
| ~~
| ~~~~~~~~~~~~~~~~~
17 | println(AAaa{1} != Aaa{1})
18 | println(Aaa{1} != AAaa{1})
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:17:18: error: possible type mismatch of compared values of `!=` operation
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:17:10: error: possible type mismatch of compared values of `!=` operation
15 | println(Aaa{0} == AAaa{0})
16 | println(AAaa{0} == Aaa{0})
17 | println(AAaa{1} != Aaa{1})
| ~~
| ~~~~~~~~~~~~~~~~~
18 | println(Aaa{1} != AAaa{1})
19 |
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:18:17: error: possible type mismatch of compared values of `!=` operation
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:18:10: error: possible type mismatch of compared values of `!=` operation
16 | println(AAaa{0} == Aaa{0})
17 | println(AAaa{1} != Aaa{1})
18 | println(Aaa{1} != AAaa{1})
| ~~
| ~~~~~~~~~~~~~~~~~
19 |
20 | arr := Arr([0])
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:21:14: error: possible type mismatch of compared values of `==` operation
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:21:10: error: possible type mismatch of compared values of `==` operation
19 |
20 | arr := Arr([0])
21 | println(arr == [0])
| ~~
| ~~~~~~~~~~
22 | println([1] == arr)
23 | println(arr != [0])
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:22:14: error: possible type mismatch of compared values of `==` operation
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:22:10: error: possible type mismatch of compared values of `==` operation
20 | arr := Arr([0])
21 | println(arr == [0])
22 | println([1] == arr)
| ~~
| ~~~~~~~~~~
23 | println(arr != [0])
24 | println([1] != arr)
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:23:14: error: possible type mismatch of compared values of `!=` operation
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:23:10: error: possible type mismatch of compared values of `!=` operation
21 | println(arr == [0])
22 | println([1] == arr)
23 | println(arr != [0])
| ~~
| ~~~~~~~~~~
24 | println([1] != arr)
25 | }
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:24:14: error: possible type mismatch of compared values of `!=` operation
vlib/v/checker/tests/eq_ne_op_wrong_type_err.vv:24:10: error: possible type mismatch of compared values of `!=` operation
22 | println([1] == arr)
23 | println(arr != [0])
24 | println([1] != arr)
| ~~
| ~~~~~~~~~~
25 | }

View File

@ -1,29 +1,29 @@
vlib/v/checker/tests/in_mismatch_type.vv:10:7: error: left operand to `in` does not match the array element type: expected `string`, not `int literal`
vlib/v/checker/tests/in_mismatch_type.vv:10:5: error: left operand to `in` does not match the array element type: expected `string`, not `int literal`
8 | }
9 | s := 'abcd'
10 | if 1 in a_s {
| ~~
| ~~~~~~~~
11 | println('ok')
12 | }
vlib/v/checker/tests/in_mismatch_type.vv:13:7: error: left operand to `in` does not match the map key type: expected `string`, not `int literal`
vlib/v/checker/tests/in_mismatch_type.vv:13:5: error: left operand to `in` does not match the map key type: expected `string`, not `int literal`
11 | println('ok')
12 | }
13 | if 2 in m {
| ~~
| ~~~~~~
14 | println('yeah')
15 | }
vlib/v/checker/tests/in_mismatch_type.vv:16:7: error: left operand to `in` does not match: expected `string`, not `int literal`
vlib/v/checker/tests/in_mismatch_type.vv:16:5: error: left operand to `in` does not match: expected `string`, not `int literal`
14 | println('yeah')
15 | }
16 | if 3 in s {
| ~~
| ~~~~~~
17 | println('dope')
18 | }
vlib/v/checker/tests/in_mismatch_type.vv:19:9: error: left operand to `in` does not match: expected `string`, not `rune`
vlib/v/checker/tests/in_mismatch_type.vv:19:5: error: left operand to `in` does not match: expected `string`, not `rune`
17 | println('dope')
18 | }
19 | if `a` in s {
| ~~
| ~~~~~~~~
20 | println("oh no :'(")
21 | }
vlib/v/checker/tests/in_mismatch_type.vv:22:7: error: `in` can only be used with an array/map/string
@ -33,45 +33,45 @@ vlib/v/checker/tests/in_mismatch_type.vv:22:7: error: `in` can only be used with
| ~~
23 | println('right')
24 | }
vlib/v/checker/tests/in_mismatch_type.vv:25:12: error: left operand to `in` does not match the map key type: expected `string`, not `Int`
vlib/v/checker/tests/in_mismatch_type.vv:25:5: error: left operand to `in` does not match the map key type: expected `string`, not `Int`
23 | println('right')
24 | }
25 | if Int(2) in m {
| ~~
| ~~~~~~~~~~~
26 | println('yeah')
27 | }
vlib/v/checker/tests/in_mismatch_type.vv:28:9: error: left operand to `in` does not match the array element type: expected `int`, not `string`
vlib/v/checker/tests/in_mismatch_type.vv:28:5: error: left operand to `in` does not match the array element type: expected `int`, not `string`
26 | println('yeah')
27 | }
28 | if '3' in a_i {
| ~~
| ~~~~~~~~~~
29 | println('sure')
30 | }
vlib/v/checker/tests/in_mismatch_type.vv:31:9: error: left operand to `in` does not match the array element type: expected `int`, not `string`
vlib/v/checker/tests/in_mismatch_type.vv:31:5: error: left operand to `in` does not match the array element type: expected `int`, not `string`
29 | println('sure')
30 | }
31 | if '2' in a_i {
| ~~
| ~~~~~~~~~~
32 | println('all right')
33 | }
vlib/v/checker/tests/in_mismatch_type.vv:34:7: error: left operand to `!in` does not match the array element type: expected `string`, not `int literal`
vlib/v/checker/tests/in_mismatch_type.vv:34:5: error: left operand to `!in` does not match the array element type: expected `string`, not `int literal`
32 | println('all right')
33 | }
34 | if 1 !in a_s {
| ~~~
| ~~~~~~~~~
35 | println('ok')
36 | }
vlib/v/checker/tests/in_mismatch_type.vv:37:9: error: left operand to `!in` does not match the array element type: expected `int`, not `string`
vlib/v/checker/tests/in_mismatch_type.vv:37:5: error: left operand to `!in` does not match the array element type: expected `int`, not `string`
35 | println('ok')
36 | }
37 | if '1' !in a_i {
| ~~~
| ~~~~~~~~~~~
38 | println('good')
39 | }
vlib/v/checker/tests/in_mismatch_type.vv:41:7: error: left operand to `!in` does not match the map key type: expected `string`, not `int literal`
vlib/v/checker/tests/in_mismatch_type.vv:41:5: error: left operand to `!in` does not match the map key type: expected `string`, not `int literal`
39 | }
40 |
41 | if 5 !in m {
| ~~~
| ~~~~~~~
42 | println('yay')
43 | }

View File

@ -1,15 +1,15 @@
vlib/v/checker/tests/infix_err.vv:7:8: error: mismatched types `string` and `?string`
vlib/v/checker/tests/infix_err.vv:7:5: error: mismatched types `string` and `?string`
5 | return none
6 | }
7 | _ = '' + f()
| ^
| ~~~~~~~~
8 | _ = f() + ''
9 | _ = f() + f()
vlib/v/checker/tests/infix_err.vv:8:9: error: mismatched types `?string` and `string`
vlib/v/checker/tests/infix_err.vv:8:5: error: mismatched types `?string` and `string`
6 | }
7 | _ = '' + f()
8 | _ = f() + ''
| ^
| ~~~~~~~~
9 | _ = f() + f()
10 |
vlib/v/checker/tests/infix_err.vv:9:9: error: `+` cannot be used with `?string`
@ -26,11 +26,11 @@ vlib/v/checker/tests/infix_err.vv:11:7: error: `+` cannot be used with `?int`
| ^
12 | _ = int(0) + g() // FIXME not detected
13 | _ = g() + int(3)
vlib/v/checker/tests/infix_err.vv:12:12: error: unwrapped optional cannot be used in an infix expression
vlib/v/checker/tests/infix_err.vv:12:5: error: unwrapped optional cannot be used in an infix expression
10 |
11 | _ = 4 + g()
12 | _ = int(0) + g() // FIXME not detected
| ^
| ~~~~~~~~~~~~
13 | _ = g() + int(3)
14 | _ = g() + 3
vlib/v/checker/tests/infix_err.vv:13:9: error: `+` cannot be used with `?int`
@ -79,3 +79,4 @@ vlib/v/checker/tests/infix_err.vv:24:2: error: use `()` to make the boolean expr
23 | && 2 == 2 || 3 == 3
24 | && 4 == 4
| ~~

View File

@ -5,11 +5,11 @@ vlib/v/checker/tests/method_op_alias_err.vv:4:18: error: expected `Foo` not `Foo
| ~~~~
5 | return Foo2(f + f1)
6 | }
vlib/v/checker/tests/method_op_alias_err.vv:5:19: error: infix expr: cannot use `string` (right expression) as `string`
vlib/v/checker/tests/method_op_alias_err.vv:5:17: error: infix expr: cannot use `string` (right expression) as `string`
3 |
4 | fn (f Foo) + (f1 Foo2) Foo2 {
5 | return Foo2(f + f1)
| ^
| ~~~~~~
6 | }
7 |
vlib/v/checker/tests/method_op_alias_err.vv:8:1: error: cannot define operator methods on type alias for `string`
@ -40,3 +40,4 @@ vlib/v/checker/tests/method_op_alias_err.vv:16:6: error: cannot use operator met
| ~~
17 | println(f)
18 | }

View File

@ -26,25 +26,25 @@ vlib/v/checker/tests/method_op_err.vv:22:1: error: argument cannot be `mut` for
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 | return User{}
24 | }
vlib/v/checker/tests/method_op_err.vv:32:24: error: infix expr: cannot use `Foo` (right expression) as `User`
vlib/v/checker/tests/method_op_err.vv:32:13: error: infix expr: cannot use `Foo` (right expression) as `User`
30 | fn main() {
31 | println(User{3, 4})
32 | println(User{3, 4} - Foo{3, 3})
| ^
| ~~~~~~~~~~~~~~~~~~~~~~
33 | println(User{3, 2} < User{2, 4})
34 | println(User{3, 4} < Foo{3, 4})
vlib/v/checker/tests/method_op_err.vv:33:24: error: undefined operation `User` < `User`
vlib/v/checker/tests/method_op_err.vv:33:13: error: undefined operation `User` < `User`
31 | println(User{3, 4})
32 | println(User{3, 4} - Foo{3, 3})
33 | println(User{3, 2} < User{2, 4})
| ^
| ~~~~~~~~~~~~~~~~~~~~~~~
34 | println(User{3, 4} < Foo{3, 4})
35 | mut u := User{3, 4}
vlib/v/checker/tests/method_op_err.vv:34:24: error: mismatched types `User` and `Foo`
vlib/v/checker/tests/method_op_err.vv:34:13: error: mismatched types `User` and `Foo`
32 | println(User{3, 4} - Foo{3, 3})
33 | println(User{3, 2} < User{2, 4})
34 | println(User{3, 4} < Foo{3, 4})
| ^
| ~~~~~~~~~~~~~~~~~~~~~~
35 | mut u := User{3, 4}
36 | u += 12
vlib/v/checker/tests/method_op_err.vv:36:10: error: cannot assign to `u`: expected `User`, not `int literal`
@ -67,3 +67,4 @@ vlib/v/checker/tests/method_op_err.vv:38:7: error: operator `+` must return `Use
38 | u += User{2, 3}
| ~~
39 | }

View File

@ -2,40 +2,41 @@ vlib/v/checker/tests/minus_op_wrong_type_err.vv:3:13: error: mismatched types `A
1 | struct Aaa{}
2 | fn main() {
3 | println(Aaa{} - 10)
| ~~~~~
| ~~~~~~~~~~
4 | println(10 - Aaa{})
5 | println([1,2,3] - 10)
vlib/v/checker/tests/minus_op_wrong_type_err.vv:4:18: error: mismatched types `int literal` and `Aaa`
vlib/v/checker/tests/minus_op_wrong_type_err.vv:4:13: error: mismatched types `int literal` and `Aaa`
2 | fn main() {
3 | println(Aaa{} - 10)
4 | println(10 - Aaa{})
| ~~~~~
| ~~~~~~~~~~
5 | println([1,2,3] - 10)
6 | println(10 - [1,2,3])
vlib/v/checker/tests/minus_op_wrong_type_err.vv:5:13: error: mismatched types `[]int` and `int literal`
3 | println(Aaa{} - 10)
4 | println(10 - Aaa{})
5 | println([1,2,3] - 10)
| ~~~~~~~
| ~~~~~~~~~~~~
6 | println(10 - [1,2,3])
7 | a := map[string]int
vlib/v/checker/tests/minus_op_wrong_type_err.vv:6:18: error: mismatched types `int literal` and `[]int`
vlib/v/checker/tests/minus_op_wrong_type_err.vv:6:13: error: mismatched types `int literal` and `[]int`
4 | println(10 - Aaa{})
5 | println([1,2,3] - 10)
6 | println(10 - [1,2,3])
| ~~~~~~~
| ~~~~~~~~~~~~
7 | a := map[string]int
8 | println(a - 10)
vlib/v/checker/tests/minus_op_wrong_type_err.vv:8:13: error: mismatched types `map[string]int` and `int literal`
6 | println(10 - [1,2,3])
7 | a := map[string]int
8 | println(a - 10)
| ^
| ~~~~~~
9 | println(10 - a)
10 | }
vlib/v/checker/tests/minus_op_wrong_type_err.vv:9:18: error: mismatched types `int literal` and `map[string]int`
vlib/v/checker/tests/minus_op_wrong_type_err.vv:9:13: error: mismatched types `int literal` and `map[string]int`
7 | a := map[string]int
8 | println(a - 10)
9 | println(10 - a)
| ^
| ~~~~~~
10 | }

View File

@ -1,14 +1,15 @@
vlib/v/checker/tests/mismatched_ptr_op_ptr.vv:5:18: error: mismatched types `&string` and `string`
vlib/v/checker/tests/mismatched_ptr_op_ptr.vv:5:17: 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`
vlib/v/checker/tests/mismatched_ptr_op_ptr.vv:6:17: error: mismatched types `&string` and `&string`
4 | b := &a
5 | println(b+*b)
6 | println(b+b)
| ^
| ~~~
7 | }
8 | }

View File

@ -16,40 +16,41 @@ vlib/v/checker/tests/mod_op_wrong_type_err.vv:5:10: error: mismatched types `[]i
3 | println(0.5 % 1)
4 | println(1 % 0.5)
5 | println([1,2,3] % 1)
| ~~~~~~~
| ~~~~~~~~~~~
6 | println(1 % [1,2,3])
7 | a := Aaa{}
vlib/v/checker/tests/mod_op_wrong_type_err.vv:6:14: error: mismatched types `int literal` and `[]int`
vlib/v/checker/tests/mod_op_wrong_type_err.vv:6:10: error: mismatched types `int literal` and `[]int`
4 | println(1 % 0.5)
5 | println([1,2,3] % 1)
6 | println(1 % [1,2,3])
| ~~~~~~~
| ~~~~~~~~~~~
7 | a := Aaa{}
8 | println(a % 1)
vlib/v/checker/tests/mod_op_wrong_type_err.vv:8:10: error: mismatched types `Aaa` and `int literal`
6 | println(1 % [1,2,3])
7 | a := Aaa{}
8 | println(a % 1)
| ^
| ~~~~~
9 | println(1 % a)
10 | b := map[string]int
vlib/v/checker/tests/mod_op_wrong_type_err.vv:9:14: error: mismatched types `int literal` and `Aaa`
vlib/v/checker/tests/mod_op_wrong_type_err.vv:9:10: error: mismatched types `int literal` and `Aaa`
7 | a := Aaa{}
8 | println(a % 1)
9 | println(1 % a)
| ^
| ~~~~~
10 | b := map[string]int
11 | println(b % 1)
vlib/v/checker/tests/mod_op_wrong_type_err.vv:11:10: error: mismatched types `map[string]int` and `int literal`
9 | println(1 % a)
10 | b := map[string]int
11 | println(b % 1)
| ^
| ~~~~~
12 | println(1 % b)
13 | }
vlib/v/checker/tests/mod_op_wrong_type_err.vv:12:14: error: mismatched types `int literal` and `map[string]int`
vlib/v/checker/tests/mod_op_wrong_type_err.vv:12:10: error: mismatched types `int literal` and `map[string]int`
10 | b := map[string]int
11 | println(b % 1)
12 | println(1 % b)
| ^
| ~~~~~
13 | }

View File

@ -2,55 +2,56 @@ vlib/v/checker/tests/mul_op_wrong_type_err.vv:5:13: error: mismatched types `Aaa
3 | struct Aaa{}
4 | fn main() {
5 | println(Aaa{} * 10)
| ~~~~~
| ~~~~~~~~~~
6 | println(10 * Aaa{})
7 | println([1,2,3] * 10)
vlib/v/checker/tests/mul_op_wrong_type_err.vv:6:18: error: mismatched types `int literal` and `Aaa`
vlib/v/checker/tests/mul_op_wrong_type_err.vv:6:13: error: mismatched types `int literal` and `Aaa`
4 | fn main() {
5 | println(Aaa{} * 10)
6 | println(10 * Aaa{})
| ~~~~~
| ~~~~~~~~~~
7 | println([1,2,3] * 10)
8 | println(10 * [1,2,3])
vlib/v/checker/tests/mul_op_wrong_type_err.vv:7:13: error: mismatched types `[]int` and `int literal`
5 | println(Aaa{} * 10)
6 | println(10 * Aaa{})
7 | println([1,2,3] * 10)
| ~~~~~~~
| ~~~~~~~~~~~~
8 | println(10 * [1,2,3])
9 | a := map[string]int
vlib/v/checker/tests/mul_op_wrong_type_err.vv:8:18: error: mismatched types `int literal` and `[]int`
vlib/v/checker/tests/mul_op_wrong_type_err.vv:8:13: error: mismatched types `int literal` and `[]int`
6 | println(10 * Aaa{})
7 | println([1,2,3] * 10)
8 | println(10 * [1,2,3])
| ~~~~~~~
| ~~~~~~~~~~~~
9 | a := map[string]int
10 | println(a * 10)
vlib/v/checker/tests/mul_op_wrong_type_err.vv:10:13: error: mismatched types `map[string]int` and `int literal`
8 | println(10 * [1,2,3])
9 | a := map[string]int
10 | println(a * 10)
| ^
| ~~~~~~
11 | println(10 * a)
12 | c1 := cmplx.complex(1,-2)
vlib/v/checker/tests/mul_op_wrong_type_err.vv:11:18: error: mismatched types `int literal` and `map[string]int`
vlib/v/checker/tests/mul_op_wrong_type_err.vv:11:13: error: mismatched types `int literal` and `map[string]int`
9 | a := map[string]int
10 | println(a * 10)
11 | println(10 * a)
| ^
| ~~~~~~
12 | c1 := cmplx.complex(1,-2)
13 | c2 := c1 * 2.0
vlib/v/checker/tests/mul_op_wrong_type_err.vv:13:11: error: infix expr: cannot use `float literal` (right expression) as `math.complex.Complex`
vlib/v/checker/tests/mul_op_wrong_type_err.vv:13:8: error: infix expr: cannot use `float literal` (right expression) as `math.complex.Complex`
11 | println(10 * a)
12 | c1 := cmplx.complex(1,-2)
13 | c2 := c1 * 2.0
| ^
| ~~~~~~~~
14 | println(c2)
15 | c3 := 2.0 * c1
vlib/v/checker/tests/mul_op_wrong_type_err.vv:15:12: error: infix expr: cannot use `math.complex.Complex` (right expression) as `float literal`
vlib/v/checker/tests/mul_op_wrong_type_err.vv:15:8: error: infix expr: cannot use `math.complex.Complex` (right expression) as `float literal`
13 | c2 := c1 * 2.0
14 | println(c2)
15 | c3 := 2.0 * c1
| ^
| ~~~~~~~~
16 | println(c3)
17 | }

View File

@ -1,5 +1,6 @@
vlib/v/checker/tests/unwrapped_optional_infix.vv:5:16: error: unwrapped optional cannot be used in an infix expression
vlib/v/checker/tests/unwrapped_optional_infix.vv:5:9: error: unwrapped optional cannot be used in an infix expression
3 | }
4 |
5 | println(test() == "")
| ~~
| ~~~~~~~~~~~~