mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
258ff73efd
commit
ad76c9c719
@ -931,6 +931,9 @@ pub fn (mut c Checker) check_expr_opt_call(expr ast.Expr, ret_type ast.Type) ast
|
|||||||
} else if expr.or_block.kind == .propagate_option {
|
} else if expr.or_block.kind == .propagate_option {
|
||||||
c.error('unexpected `?`, the function `$expr.name` does not return an optional',
|
c.error('unexpected `?`, the function `$expr.name` does not return an optional',
|
||||||
expr.or_block.pos)
|
expr.or_block.pos)
|
||||||
|
} else if expr.or_block.kind == .propagate_result {
|
||||||
|
c.error('unexpected `!`, the function `$expr.name` does not return an optional',
|
||||||
|
expr.or_block.pos)
|
||||||
}
|
}
|
||||||
} else if expr is ast.IndexExpr {
|
} else if expr is ast.IndexExpr {
|
||||||
if expr.or_expr.kind != .absent {
|
if expr.or_expr.kind != .absent {
|
||||||
@ -2120,6 +2123,9 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type {
|
|||||||
} else if node.or_block.kind == .propagate_option {
|
} else if node.or_block.kind == .propagate_option {
|
||||||
c.error('unexpected `?`, the function `$node.name` does neither return an optional nor a result',
|
c.error('unexpected `?`, the function `$node.name` does neither return an optional nor a result',
|
||||||
node.or_block.pos)
|
node.or_block.pos)
|
||||||
|
} else if node.or_block.kind == .propagate_result {
|
||||||
|
c.error('unexpected `!`, the function `$node.name` does neither return an optional nor a result',
|
||||||
|
node.or_block.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if node.or_block.kind != .absent {
|
if node.or_block.kind != .absent {
|
||||||
|
7
vlib/v/checker/tests/result_missing_propagate_err.out
Normal file
7
vlib/v/checker/tests/result_missing_propagate_err.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/result_missing_propagate_err.vv:6:7: error: result() returns a result, so it should have either an `or {}` block, or `!` at the end
|
||||||
|
4 |
|
||||||
|
5 | fn main() {
|
||||||
|
6 | a := result()
|
||||||
|
| ~~~~~~~~
|
||||||
|
7 | println(a)
|
||||||
|
8 | }
|
8
vlib/v/checker/tests/result_missing_propagate_err.vv
Normal file
8
vlib/v/checker/tests/result_missing_propagate_err.vv
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fn result() !int {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
a := result()
|
||||||
|
println(a)
|
||||||
|
}
|
@ -1,7 +1,14 @@
|
|||||||
vlib/v/checker/tests/wrong_propagate_ret_type.vv:6:17: error: to propagate the optional call, `opt_call` must return an optional
|
vlib/v/checker/tests/wrong_propagate_ret_type.vv:10:17: error: to propagate the optional call, `opt_call` must return an optional
|
||||||
4 |
|
8 |
|
||||||
5 | fn opt_call() int {
|
9 | fn opt_call() int {
|
||||||
6 | a := ret_none()?
|
10 | a := ret_none()?
|
||||||
| ^
|
| ^
|
||||||
7 | return a
|
11 | return a
|
||||||
8 | }
|
12 | }
|
||||||
|
vlib/v/checker/tests/wrong_propagate_ret_type.vv:15:17: error: unexpected `!`, the function `ret_bool` does neither return an optional nor a result
|
||||||
|
13 |
|
||||||
|
14 | fn res_call() bool {
|
||||||
|
15 | a := ret_bool()!
|
||||||
|
| ^
|
||||||
|
16 | return a
|
||||||
|
17 | }
|
||||||
|
@ -2,7 +2,16 @@ fn ret_none() ?int {
|
|||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ret_bool() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
fn opt_call() int {
|
fn opt_call() int {
|
||||||
a := ret_none()?
|
a := ret_none()?
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn res_call() bool {
|
||||||
|
a := ret_bool()!
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user