mirror of
https://github.com/vlang/v.git
synced 2025-09-13 09:25:45 -04:00
This commit is contained in:
parent
387f717004
commit
ec45e4736a
@ -424,7 +424,7 @@ fn (mut p Parser) parse_type() ast.Type {
|
|||||||
is_required_field := p.inside_struct_field_decl && p.tok.kind == .lsbr
|
is_required_field := p.inside_struct_field_decl && p.tok.kind == .lsbr
|
||||||
&& p.peek_tok.kind == .name && p.peek_tok.lit == 'required'
|
&& 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
|
mut typ := ast.void_type
|
||||||
if is_option {
|
if is_option {
|
||||||
typ = typ.set_flag(.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…
x
Reference in New Issue
Block a user