1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: use ? instead of ?void errpr

This commit is contained in:
yuyi 2020-06-02 23:24:24 +08:00 committed by GitHub
parent b0f66a4e05
commit 1386c5df13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/void_optional_err.v:1:16: error: use `?` instead of `?void`
1 | fn ret_void() ?void {
| ~~~~
2 | return error('error')
3 | }

View File

@ -0,0 +1,7 @@
fn ret_void() ?void {
return error('error')
}
fn main() {
_ := ret_void() or { panic('$err') }
}

View File

@ -134,7 +134,11 @@ pub fn (mut p Parser) parse_type() table.Type {
}
mut typ := table.void_type
if p.tok.kind != .lcbr {
pos := p.tok.position()
typ = p.parse_any_type(language, nr_muls > 0)
if typ == table.void_type {
p.error_with_pos('use `?` instead of `?void`', pos)
}
}
if is_optional {
typ = typ.set_flag(.optional)

View File

@ -274,7 +274,7 @@ fn test_multi_return_opt() {
}
}
*/
fn foo() ?void {
fn foo() ? {
return error('something')
}