mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
Merge fa21ac80468faf05a165e93f73f6f07cc00ec1a5 into 65a493d0239007498e63030b0dd3bb0893f632bd
This commit is contained in:
commit
d957ac84ef
@ -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