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

cgen: fix generic json bug (#6731)

This commit is contained in:
Daniel Däschle
2020-11-04 09:21:30 +01:00
committed by GitHub
parent cc4bb71f29
commit 25912673a9
2 changed files with 17 additions and 4 deletions

View File

@ -29,6 +29,18 @@ fn test_simple() {
assert y.title == .worker
}
fn bar<T>(payload string) ?Bar { // ?T doesn't work currently
result := json.decode(T, payload)?
return result
}
struct Bar {
x string
}
fn test_generic() {
result := bar<Bar>('{"x":"test"}') or { Bar{} }
assert result.x == 'test'
}
struct User2 {
age int
nums []int