cgen,json: fix default initialization of structs with options (#23263)

This commit is contained in:
Felipe Pena 2024-12-25 14:42:48 -03:00 committed by GitHub
parent f27181e81b
commit 80bae08c9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 69 additions and 33 deletions

View 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)
})'
}