v
v copied to clipboard
C Error. Compiler bug when directly passing index from json (and alike?) data
Describe the bug
I didn't know a good and short title that would fit. I hope an example can do most of the talking for me.
import x.json2
import net.http
struct SomeStruct {
title string
}
fn main() {
resp := http.get('https://jsonplaceholder.typicode.com/posts/1')!
raw_data := json2.raw_decode(resp.body)!
data := raw_data as map[string]json2.Any
mut ss := map[int]SomeStruct{}
s := SomeStruct{
title: data['title']!.str()
}
// Compiler bug putting `data['id']!.int()` directly into ss[].
ss[data['id']!.int()] = s
// No issues with id in variable
// id := data['id']!.int()
// ss[id] = s
println(ss)
}
Got a few of these C errors this week, I report more when I have time.
Expected Behavior
Directly passing the index should work.
Current Behavior
Compiler Bug.
Reproduction Steps
Run code example above.
Possible Solution
No response
Additional Information/Context
No response
V version
0.3.3 6e1e406
Environment details (OS name and version, etc.)
linux arch