checker: make optional array element an error (#9343)
parent
a6c2c5ba88
commit
4ae2c22c18
|
@ -3097,7 +3097,7 @@ pub fn (mut c Checker) array_init(mut array_init ast.ArrayInit) table.Type {
|
||||||
// println('ex $c.expected_type')
|
// println('ex $c.expected_type')
|
||||||
// }
|
// }
|
||||||
for i, expr in array_init.exprs {
|
for i, expr in array_init.exprs {
|
||||||
typ := c.expr(expr)
|
typ := c.check_expr_opt_call(expr, c.expr(expr))
|
||||||
array_init.expr_types << typ
|
array_init.expr_types << typ
|
||||||
// The first element's type
|
// The first element's type
|
||||||
if expecting_interface_array {
|
if expecting_interface_array {
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
vlib/v/checker/tests/optional_fn_err.vv:11:2: error: foo() returns an option, so it should have either an `or {}` block, or `?` at the end
|
||||||
|
9 | fn main() {
|
||||||
|
10 | // Calling foo() without ? or an or block, should be an error.
|
||||||
|
11 | foo()
|
||||||
|
| ~~~~~
|
||||||
|
12 |
|
||||||
|
13 | _ := bar()
|
||||||
|
vlib/v/checker/tests/optional_fn_err.vv:13:7: error: bar() returns an option, so it should have either an `or {}` block, or `?` at the end
|
||||||
|
11 | foo()
|
||||||
|
12 |
|
||||||
|
13 | _ := bar()
|
||||||
|
| ~~~~~
|
||||||
|
14 | _ := [bar()]
|
||||||
|
15 | }
|
||||||
|
vlib/v/checker/tests/optional_fn_err.vv:14:8: error: bar() returns an option, so it should have either an `or {}` block, or `?` at the end
|
||||||
|
12 |
|
||||||
|
13 | _ := bar()
|
||||||
|
14 | _ := [bar()]
|
||||||
|
| ~~~~~
|
||||||
|
15 | }
|
|
@ -2,7 +2,14 @@ fn foo() ? {
|
||||||
println('foo is called')
|
println('foo is called')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bar() ?int {
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Calling foo() without ? or an or block, should be an error.
|
// Calling foo() without ? or an or block, should be an error.
|
||||||
foo()
|
foo()
|
||||||
|
|
||||||
|
_ := bar()
|
||||||
|
_ := [bar()]
|
||||||
}
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
vlib/v/checker/tests/optional_void_called_as_normal.vv:7:2: error: foo() returns an option, so it should have either an `or {}` block, or `?` at the end
|
|
||||||
5 | fn main() {
|
|
||||||
6 | // Calling foo() without ? or an or block, should be an error.
|
|
||||||
7 | foo()
|
|
||||||
| ~~~~~
|
|
||||||
8 | }
|
|
Loading…
Reference in New Issue