mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix struct field fn type with default value
This commit is contained in:
parent
65a493d023
commit
9de852160a
@ -424,7 +424,7 @@ fn (mut p Parser) parse_type() ast.Type {
|
||||
is_required_field := p.inside_struct_field_decl && p.tok.kind == .lsbr
|
||||
&& p.peek_tok.kind == .name && p.peek_tok.lit == 'required'
|
||||
|
||||
if p.tok.line_nr > line_nr || p.tok.kind in [.comma, .rpar] || is_required_field {
|
||||
if p.tok.line_nr > line_nr || p.tok.kind in [.comma, .rpar, .assign] || is_required_field {
|
||||
mut typ := ast.void_type
|
||||
if is_option {
|
||||
typ = typ.set_flag(.option)
|
||||
|
25
vlib/v/tests/struct_field_default_fn_type_value_init_test.v
Normal file
25
vlib/v/tests/struct_field_default_fn_type_value_init_test.v
Normal file
@ -0,0 +1,25 @@
|
||||
struct Flip {
|
||||
name string = 'NULL'
|
||||
execute fn () ! = unsafe { nil }
|
||||
}
|
||||
|
||||
fn (flip Flip) exec() ! {
|
||||
if isnil(flip.execute) {
|
||||
return
|
||||
}
|
||||
|
||||
println('Executing ${flip.name}')
|
||||
flip.execute()!
|
||||
}
|
||||
|
||||
fn test_struct_field_default_fn_type_value() {
|
||||
fl := Flip{
|
||||
name: 'a function'
|
||||
execute: fn () ! {
|
||||
println('Hello, World!')
|
||||
}
|
||||
}
|
||||
|
||||
fl.exec()!
|
||||
assert true
|
||||
}
|
Loading…
Reference in New Issue
Block a user