-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unknown type for json.decode with nested generics #22220
Labels
Bug
This tag is applied to issues which reports bugs.
Modules: JSON
Bugs/feature requests, that are related to `json` and `x.json2` modules.
Comments
esquerbatua
added
Bug
This tag is applied to issues which reports bugs.
Modules: JSON
Bugs/feature requests, that are related to `json` and `x.json2` modules.
labels
Sep 26, 2024
With x.json2 it's failing also: import x.json2
struct Chocolate {
with_nuts bool
}
struct Box[T] {
items []T
}
fn open[T](text string) []T {
// Doesn't compile (not without another explicit type declaration) :
box := string_decode[Box[T]](text)
// Compiles without the explicit type declaration :
// box := json.decode(Box[T], text) or { panic(err) }
return box.items
}
fn string_decode[L](text string) L {
result := json2.decode[L](text) or { panic(err) }
return result
}
fn main() {
// Explicitly declare type
// _ := Box[Chocolate]{}
box_text := '{"items": [
{},
{"with_nuts": true},
{}
]}'
bonbons := open[Chocolate](box_text)
println(bonbons)
assert bonbons.len == 3
assert bonbons[0].with_nuts == false
assert bonbons[1].with_nuts == true
assert bonbons[2].with_nuts == false
} Part of the C code: |
esquerbatua
added
Modules: x.json2
Bugs related to *only* x.json2 (the pure V implementation)
and removed
Modules: x.json2
Bugs related to *only* x.json2 (the pure V implementation)
labels
Sep 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Bug
This tag is applied to issues which reports bugs.
Modules: JSON
Bugs/feature requests, that are related to `json` and `x.json2` modules.
Could be linked to #19045, but there are no anonymous functions here.
Probably some extension of #18308 as well.
V doctor:
What did you do?
https://play.vlang.io/p/685a11aa5a
./v -g -o vdbg cmd/v && ./vdbg pg-generics.v
What did you expect to see?
No error, the type
Box[Chocolate]
should not be unknownWhat did you see instead?
I also saw that declaring explicitly a variable with that type, or using directly json.decode would avoid the error.
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: