mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: fix error for json encoding sumtype value (#13248)
This commit is contained in:
parent
839ae6b2e4
commit
e66e35ced1
@ -430,3 +430,27 @@ fn test_omit_empty() {
|
||||
// println('omitempty:')
|
||||
// println(json.encode_pretty(foo))
|
||||
}
|
||||
|
||||
struct Asdasd {
|
||||
data GamePacketData
|
||||
}
|
||||
|
||||
type GamePacketData = GPEquipItem | GPScale
|
||||
|
||||
struct GPScale {
|
||||
value f32
|
||||
}
|
||||
|
||||
struct GPEquipItem {
|
||||
name string
|
||||
}
|
||||
|
||||
fn create_game_packet(data &GamePacketData) string {
|
||||
return json.encode(data)
|
||||
}
|
||||
|
||||
fn test_encode_sumtype_defined_ahead() {
|
||||
ret := create_game_packet(&GamePacketData(GPScale{}))
|
||||
println(ret)
|
||||
assert ret == '{"value":0,"_type":"GPScale"}'
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ $enc_fn_dec {
|
||||
fn (mut g Gen) gen_sumtype_enc_dec(sym ast.TypeSymbol, mut enc strings.Builder, mut dec strings.Builder) {
|
||||
info := sym.info as ast.SumType
|
||||
type_var := g.new_tmp_var()
|
||||
typ := sym.idx
|
||||
typ := g.table.type_idxs[sym.name]
|
||||
|
||||
// DECODING (inline)
|
||||
$if !json_no_inline_sumtypes ? {
|
||||
|
Loading…
Reference in New Issue
Block a user