mirror of
https://github.com/vlang/v.git
synced 2025-09-13 17:36:52 -04:00
checker: fix missing option and result wrong type return type definition (#21626)
This commit is contained in:
parent
1096173bd3
commit
6d2c3a9caa
5
vlib/v/checker/tests/option_and_result_err.out
Normal file
5
vlib/v/checker/tests/option_and_result_err.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/option_and_result_err.vv:1:11: error: the type must be Option or Result
|
||||
1 | fn foo() !?i32 {
|
||||
| ^
|
||||
2 | return 6
|
||||
3 | }
|
3
vlib/v/checker/tests/option_and_result_err.vv
Normal file
3
vlib/v/checker/tests/option_and_result_err.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn foo() !?i32 {
|
||||
return 6
|
||||
}
|
@ -465,9 +465,22 @@ fn (mut p Parser) parse_type() ast.Type {
|
||||
if p.tok.kind == .question {
|
||||
p.next()
|
||||
is_option = true
|
||||
if p.tok.kind == .not {
|
||||
p.next()
|
||||
is_result = true
|
||||
}
|
||||
} else if p.tok.kind == .not {
|
||||
p.next()
|
||||
is_result = true
|
||||
if p.tok.kind == .question {
|
||||
p.next()
|
||||
is_option = true
|
||||
}
|
||||
}
|
||||
|
||||
if is_option && is_result {
|
||||
p.error_with_pos('the type must be Option or Result', p.prev_tok.pos())
|
||||
return 0
|
||||
}
|
||||
|
||||
if is_option || is_result {
|
||||
|
@ -1,5 +1,5 @@
|
||||
vlib/v/parser/tests/option_result_err.vv:2:2: error: invalid expression: unexpected keyword `return`
|
||||
vlib/v/parser/tests/option_result_err.vv:1:11: error: the type must be Option or Result
|
||||
1 | fn abc() ?!string {
|
||||
| ^
|
||||
2 | return ''
|
||||
| ~~~~~~
|
||||
3 | }
|
||||
|
@ -1,5 +1,5 @@
|
||||
vlib/v/parser/tests/result_option_err.vv:2:2: error: invalid expression: unexpected keyword `return`
|
||||
vlib/v/parser/tests/result_option_err.vv:1:11: error: the type must be Option or Result
|
||||
1 | fn abc() ?!string {
|
||||
| ^
|
||||
2 | return ''
|
||||
| ~~~~~~
|
||||
3 | }
|
||||
|
Loading…
x
Reference in New Issue
Block a user