mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
cgen,json: fix default initialization of structs with options (#23263)
This commit is contained in:
parent
f27181e81b
commit
80bae08c9a
3 changed files with 69 additions and 33 deletions
20
vlib/json/tests/json_decode_option_alias_test.v
Normal file
20
vlib/json/tests/json_decode_option_alias_test.v
Normal file
|
@ -0,0 +1,20 @@
|
|||
import json
|
||||
|
||||
struct Empty {}
|
||||
|
||||
struct SomeStruct {
|
||||
random_field_a ?string
|
||||
random_field_b ?string
|
||||
empty_field ?Empty
|
||||
}
|
||||
|
||||
type Alias = SomeStruct
|
||||
|
||||
fn test_main() {
|
||||
data := json.decode(Alias, '{"empty_field":{}}')!
|
||||
assert data.str() == 'Alias(SomeStruct{
|
||||
random_field_a: Option(none)
|
||||
random_field_b: Option(none)
|
||||
empty_field: Option(none)
|
||||
})'
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue