mirror of
https://github.com/vlang/v.git
synced 2025-09-08 14:51:53 -04:00
parent
52ae3f2476
commit
8f15d65168
@ -2767,7 +2767,8 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
|
||||
g.expr_with_cast(arg.expr, arg_typ, expected_type)
|
||||
g.write('.data')
|
||||
return
|
||||
} else if arg.expr is ast.Ident && arg_sym.info is ast.Struct && arg_sym.info.is_anon {
|
||||
} else if arg.expr is ast.Ident && arg_sym.info is ast.Struct && arg_sym.info.is_anon
|
||||
&& !expected_type.has_flag(.generic) {
|
||||
// make anon struct struct compatible with another anon struct declaration
|
||||
g.write('*(${g.cc_type(expected_type, false)}*)&')
|
||||
}
|
||||
|
24
vlib/x/json2/tests/encode_anon_struct_test.v
Normal file
24
vlib/x/json2/tests/encode_anon_struct_test.v
Normal file
@ -0,0 +1,24 @@
|
||||
import x.json2
|
||||
|
||||
struct Disk {
|
||||
dev string
|
||||
size ?struct {
|
||||
value u64
|
||||
}
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
disk := Disk{
|
||||
size: struct {
|
||||
value: 123
|
||||
}
|
||||
}
|
||||
disk_str := json2.encode[Disk](disk)
|
||||
assert disk_str == '{"dev":"","size":{"value":123}}'
|
||||
}
|
||||
|
||||
fn test_none() {
|
||||
disk := Disk{}
|
||||
disk_str := json2.encode[Disk](disk)
|
||||
assert disk_str == '{"dev":""}'
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user