1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix json decode with optional argument (fix #13943) (#13958)

This commit is contained in:
yuyi
2022-04-07 00:34:22 +08:00
committed by GitHub
parent 56e6fd01c5
commit c9dcdf6744
3 changed files with 38 additions and 4 deletions

View File

@@ -0,0 +1,12 @@
import json
struct TodoDto {
foo int
}
fn test_decode_with_encode_arg() ? {
body := TodoDto{}
ret := json.decode(TodoDto, json.encode(body)) ?
println(ret)
assert ret.foo == 0
}

View File

@@ -0,0 +1,21 @@
import json
import os
struct DbConfig {
foo int
}
fn test_json_decode_with_optional_arg() {
if ret := print_info() {
println(ret)
} else {
println(err)
}
assert true
}
fn print_info() ?string {
dbconf := json.decode(DbConfig, os.read_file('dbconf.json') ?) ?
println(dbconf)
return '$dbconf'
}