mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add disallow none
operations and range (#16584)
This commit is contained in:
parent
ffc73bf643
commit
ce06c2818d
12
.github/workflows/v_apps_and_modules_compile.yml
vendored
12
.github/workflows/v_apps_and_modules_compile.yml
vendored
@ -116,6 +116,18 @@ jobs:
|
||||
|
||||
- name: Build VSL
|
||||
run: |
|
||||
echo "Installing dependencies"
|
||||
sudo apt-get install --quiet -y --no-install-recommends \
|
||||
gfortran \
|
||||
libxi-dev \
|
||||
libxcursor-dev \
|
||||
mesa-common-dev \
|
||||
liblapacke-dev \
|
||||
libopenblas-dev \
|
||||
libgc-dev \
|
||||
libgl1-mesa-dev \
|
||||
libopenmpi-dev \
|
||||
opencl-headers
|
||||
echo "Install VSL"
|
||||
v install vsl
|
||||
echo "Execute Tests using Pure V Backend"
|
||||
|
@ -60,6 +60,8 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
|
||||
c.error('range type can not be bool', node.cond.pos())
|
||||
} else if typ_idx == ast.string_type_idx || high_type_idx == ast.string_type_idx {
|
||||
c.error('range type can not be string', node.cond.pos())
|
||||
} else if typ_idx == ast.none_type_idx || high_type_idx == ast.none_type_idx {
|
||||
c.error('range type can not be none', node.cond.pos())
|
||||
}
|
||||
if high_type in [ast.int_type, ast.int_literal_type] {
|
||||
node.val_type = typ
|
||||
|
@ -62,6 +62,9 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
|
||||
left_pos := node.left.pos()
|
||||
right_pos := node.right.pos()
|
||||
left_right_pos := left_pos.extend(right_pos)
|
||||
if left_sym.kind == .none_ && right_sym.kind == .none_ {
|
||||
c.invalid_operator_error(node.op, left_type, right_type, left_right_pos)
|
||||
}
|
||||
if left_type.is_any_kind_of_pointer()
|
||||
&& node.op in [.plus, .minus, .mul, .div, .mod, .xor, .amp, .pipe] {
|
||||
if !c.pref.translated && ((right_type.is_any_kind_of_pointer() && node.op != .minus)
|
||||
|
150
vlib/v/checker/tests/invalid_none_operations_err.out
Normal file
150
vlib/v/checker/tests/invalid_none_operations_err.out
Normal file
@ -0,0 +1,150 @@
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:1:9: error: invalid operator `+` to `none` and `none`
|
||||
1 | println(none + none)
|
||||
| ~~~~~~~~~~~
|
||||
2 | println(none - none)
|
||||
3 | println(none * none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:2:9: error: invalid operator `-` to `none` and `none`
|
||||
1 | println(none + none)
|
||||
2 | println(none - none)
|
||||
| ~~~~~~~~~~~
|
||||
3 | println(none * none)
|
||||
4 | println(none / none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:3:9: error: invalid operator `*` to `none` and `none`
|
||||
1 | println(none + none)
|
||||
2 | println(none - none)
|
||||
3 | println(none * none)
|
||||
| ~~~~~~~~~~~
|
||||
4 | println(none / none)
|
||||
5 | println(none % none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:4:9: error: invalid operator `/` to `none` and `none`
|
||||
2 | println(none - none)
|
||||
3 | println(none * none)
|
||||
4 | println(none / none)
|
||||
| ~~~~~~~~~~~
|
||||
5 | println(none % none)
|
||||
6 | println(none ^ none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:5:9: error: invalid operator `%` to `none` and `none`
|
||||
3 | println(none * none)
|
||||
4 | println(none / none)
|
||||
5 | println(none % none)
|
||||
| ~~~~~~~~~~~
|
||||
6 | println(none ^ none)
|
||||
7 | println(none << none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:6:9: error: invalid operator `^` to `none` and `none`
|
||||
4 | println(none / none)
|
||||
5 | println(none % none)
|
||||
6 | println(none ^ none)
|
||||
| ~~~~~~~~~~~
|
||||
7 | println(none << none)
|
||||
8 | println(none >> none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:7:9: error: invalid operator `<<` to `none` and `none`
|
||||
5 | println(none % none)
|
||||
6 | println(none ^ none)
|
||||
7 | println(none << none)
|
||||
| ~~~~~~~~~~~~
|
||||
8 | println(none >> none)
|
||||
9 | println(none == none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:8:9: error: invalid operator `>>` to `none` and `none`
|
||||
6 | println(none ^ none)
|
||||
7 | println(none << none)
|
||||
8 | println(none >> none)
|
||||
| ~~~~~~~~~~~~
|
||||
9 | println(none == none)
|
||||
10 | println(none != none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:9:9: error: invalid operator `==` to `none` and `none`
|
||||
7 | println(none << none)
|
||||
8 | println(none >> none)
|
||||
9 | println(none == none)
|
||||
| ~~~~~~~~~~~~
|
||||
10 | println(none != none)
|
||||
11 | println(none > none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:10:9: error: invalid operator `!=` to `none` and `none`
|
||||
8 | println(none >> none)
|
||||
9 | println(none == none)
|
||||
10 | println(none != none)
|
||||
| ~~~~~~~~~~~~
|
||||
11 | println(none > none)
|
||||
12 | println(none < none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:11:9: error: invalid operator `>` to `none` and `none`
|
||||
9 | println(none == none)
|
||||
10 | println(none != none)
|
||||
11 | println(none > none)
|
||||
| ~~~~~~~~~~~
|
||||
12 | println(none < none)
|
||||
13 | println(none >= none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:12:9: error: invalid operator `<` to `none` and `none`
|
||||
10 | println(none != none)
|
||||
11 | println(none > none)
|
||||
12 | println(none < none)
|
||||
| ~~~~~~~~~~~
|
||||
13 | println(none >= none)
|
||||
14 | println(none <= none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:13:9: error: invalid operator `>=` to `none` and `none`
|
||||
11 | println(none > none)
|
||||
12 | println(none < none)
|
||||
13 | println(none >= none)
|
||||
| ~~~~~~~~~~~~
|
||||
14 | println(none <= none)
|
||||
15 | println(none && none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:14:9: error: invalid operator `<=` to `none` and `none`
|
||||
12 | println(none < none)
|
||||
13 | println(none >= none)
|
||||
14 | println(none <= none)
|
||||
| ~~~~~~~~~~~~
|
||||
15 | println(none && none)
|
||||
16 | println(none || none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:15:9: error: invalid operator `&&` to `none` and `none`
|
||||
13 | println(none >= none)
|
||||
14 | println(none <= none)
|
||||
15 | println(none && none)
|
||||
| ~~~~~~~~~~~~
|
||||
16 | println(none || none)
|
||||
17 | println(none is none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:16:9: error: invalid operator `||` to `none` and `none`
|
||||
14 | println(none <= none)
|
||||
15 | println(none && none)
|
||||
16 | println(none || none)
|
||||
| ~~~~~~~~~~~~
|
||||
17 | println(none is none)
|
||||
18 | println(none !is none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:17:9: error: invalid operator `is` to `none` and `none`
|
||||
15 | println(none && none)
|
||||
16 | println(none || none)
|
||||
17 | println(none is none)
|
||||
| ~~~~~~~~~~~~
|
||||
18 | println(none !is none)
|
||||
19 | println(none in none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:18:9: error: invalid operator `!is` to `none` and `none`
|
||||
16 | println(none || none)
|
||||
17 | println(none is none)
|
||||
18 | println(none !is none)
|
||||
| ~~~~~~~~~~~~~
|
||||
19 | println(none in none)
|
||||
20 | println(none !in none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:19:9: error: invalid operator `in` to `none` and `none`
|
||||
17 | println(none is none)
|
||||
18 | println(none !is none)
|
||||
19 | println(none in none)
|
||||
| ~~~~~~~~~~~~
|
||||
20 | println(none !in none)
|
||||
21 | println(none <- none)
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:20:9: error: invalid operator `!in` to `none` and `none`
|
||||
18 | println(none !is none)
|
||||
19 | println(none in none)
|
||||
20 | println(none !in none)
|
||||
| ~~~~~~~~~~~~~
|
||||
21 | println(none <- none)
|
||||
22 |
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:21:9: error: invalid operator `<-` to `none` and `none`
|
||||
19 | println(none in none)
|
||||
20 | println(none !in none)
|
||||
21 | println(none <- none)
|
||||
| ~~~~~~~~~~~~
|
||||
22 |
|
||||
23 | for _ in none .. none {
|
||||
vlib/v/checker/tests/invalid_none_operations_err.vv:23:10: error: range type can not be none
|
||||
21 | println(none <- none)
|
||||
22 |
|
||||
23 | for _ in none .. none {
|
||||
| ~~~~
|
||||
24 | }
|
24
vlib/v/checker/tests/invalid_none_operations_err.vv
Normal file
24
vlib/v/checker/tests/invalid_none_operations_err.vv
Normal file
@ -0,0 +1,24 @@
|
||||
println(none + none)
|
||||
println(none - none)
|
||||
println(none * none)
|
||||
println(none / none)
|
||||
println(none % none)
|
||||
println(none ^ none)
|
||||
println(none << none)
|
||||
println(none >> none)
|
||||
println(none == none)
|
||||
println(none != none)
|
||||
println(none > none)
|
||||
println(none < none)
|
||||
println(none >= none)
|
||||
println(none <= none)
|
||||
println(none && none)
|
||||
println(none || none)
|
||||
println(none is none)
|
||||
println(none !is none)
|
||||
println(none in none)
|
||||
println(none !in none)
|
||||
println(none <- none)
|
||||
|
||||
for _ in none .. none {
|
||||
}
|
Loading…
Reference in New Issue
Block a user