mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json: fix json decode with sumtype of multi array type (#14035)
This commit is contained in:
@@ -1,13 +1,21 @@
|
||||
import json
|
||||
|
||||
type Test = []string | string
|
||||
type Test = []bool | []int | []string | string
|
||||
|
||||
struct Some {
|
||||
t Test
|
||||
}
|
||||
|
||||
fn test_json_decode_with_sumtype() ? {
|
||||
v := json.decode(Some, '{"t": ["string", "string2"]}') ?
|
||||
println(v)
|
||||
assert '$v.t' == "Test(['string', 'string2'])"
|
||||
v1 := json.decode(Some, '{"t": ["string", "string2"]}') ?
|
||||
println(v1)
|
||||
assert v1.t == Test(['string', 'string2'])
|
||||
|
||||
v2 := json.decode(Some, '{"t": [11, 22]}') ?
|
||||
println(v2)
|
||||
assert v2.t == Test([11, 22])
|
||||
|
||||
v3 := json.decode(Some, '{"t": [true, false]}') ?
|
||||
println(v3)
|
||||
assert v3.t == Test([true, false])
|
||||
}
|
||||
|
Reference in New Issue
Block a user