mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
a4eb5b6356
commit
ce6bc2c26d
@ -377,6 +377,9 @@ pub fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type {
|
||||
expected_type = field_info.typ
|
||||
c.expected_type = expected_type
|
||||
expr_type = c.expr(field.expr)
|
||||
if expr_type == ast.void_type {
|
||||
c.error('`$field.expr` (no value) used as value', field.pos)
|
||||
}
|
||||
if !field_info.typ.has_flag(.optional) {
|
||||
expr_type = c.check_expr_opt_call(field.expr, expr_type)
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/struct_field_init_with_void_expr_err.vv:19:3: error: `app.test_func()` (no value) used as value
|
||||
17 | name: 'add'
|
||||
18 | description: 'Add something.'
|
||||
19 | execute: app.test_func()
|
||||
| ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
20 | }
|
||||
21 |
|
25
vlib/v/checker/tests/struct_field_init_with_void_expr_err.vv
Normal file
25
vlib/v/checker/tests/struct_field_init_with_void_expr_err.vv
Normal file
@ -0,0 +1,25 @@
|
||||
import cli { Command }
|
||||
import os
|
||||
|
||||
struct App {}
|
||||
|
||||
fn (a App) test_func() {}
|
||||
|
||||
fn main() {
|
||||
mut cmd := Command{
|
||||
name: 'cli'
|
||||
version: '0.0.1'
|
||||
}
|
||||
|
||||
app := App{}
|
||||
|
||||
mut add := Command{
|
||||
name: 'add'
|
||||
description: 'Add something.'
|
||||
execute: app.test_func()
|
||||
}
|
||||
|
||||
cmd.add_command(add)
|
||||
cmd.setup()
|
||||
cmd.parse(os.args)
|
||||
}
|
Loading…
Reference in New Issue
Block a user