checker: add error for arr1 <,>,>=,<= arr2 (#6243)

pull/6245/head
Swastik Baranwal 2020-08-28 13:38:07 +05:30 committed by GitHub
parent 88f75fc1d6
commit 39bf02ea68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -593,6 +593,11 @@ pub fn (mut c Checker) infix_expr(mut infix_expr ast.InfixExpr) table.Type {
return_type = promoted_type
}
}
.gt, .lt, .ge, .le {
if left.kind in [.array, .array_fixed] && right.kind in [.array, .array_fixed] {
c.error('only `==` and `!=` are defined on arrays', infix_expr.pos)
}
}
.left_shift {
if left.kind == .array {
// `array << elm`

View File

@ -0,0 +1,26 @@
vlib/v/checker/tests/array_cmp_err.vv:2:26: error: only `==` and `!=` are defined on arrays
1 | fn main() {
2 | println([2, 3, 4, 6] < [2, 5])
| ^
3 | println([2, 3, 4, 6] > [2, 5])
4 | println([2, 3, 1, 6] >= [3, 5, 7])
vlib/v/checker/tests/array_cmp_err.vv:3:26: error: only `==` and `!=` are defined on arrays
1 | fn main() {
2 | println([2, 3, 4, 6] < [2, 5])
3 | println([2, 3, 4, 6] > [2, 5])
| ^
4 | println([2, 3, 1, 6] >= [3, 5, 7])
5 | println([2, 3, 6, 8] <= [2, 5, 8, 9])
vlib/v/checker/tests/array_cmp_err.vv:4:26: error: only `==` and `!=` are defined on arrays
2 | println([2, 3, 4, 6] < [2, 5])
3 | println([2, 3, 4, 6] > [2, 5])
4 | println([2, 3, 1, 6] >= [3, 5, 7])
| ~~
5 | println([2, 3, 6, 8] <= [2, 5, 8, 9])
6 | }
vlib/v/checker/tests/array_cmp_err.vv:5:26: error: only `==` and `!=` are defined on arrays
3 | println([2, 3, 4, 6] > [2, 5])
4 | println([2, 3, 1, 6] >= [3, 5, 7])
5 | println([2, 3, 6, 8] <= [2, 5, 8, 9])
| ~~
6 | }

View File

@ -0,0 +1,6 @@
fn main() {
println([2, 3, 4, 6] < [2, 5])
println([2, 3, 4, 6] > [2, 5])
println([2, 3, 1, 6] >= [3, 5, 7])
println([2, 3, 6, 8] <= [2, 5, 8, 9])
}