mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix indexexpr with complex index expr (#17693)
This commit is contained in:
parent
45c0a21f46
commit
68955bb26c
@ -449,7 +449,10 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
|
||||
g.write('->val')
|
||||
}
|
||||
g.write(', &(${key_type_str}[]){')
|
||||
old_is_assign_lhs := g.is_assign_lhs
|
||||
g.is_assign_lhs = false
|
||||
g.expr(node.index)
|
||||
g.is_assign_lhs = old_is_assign_lhs
|
||||
g.write('}, &(${elem_type_str}[]){ ${zero} }))')
|
||||
} else {
|
||||
zero := g.type_default(info.value_type)
|
||||
|
25
vlib/v/tests/result_with_index_expr_test.v
Normal file
25
vlib/v/tests/result_with_index_expr_test.v
Normal file
@ -0,0 +1,25 @@
|
||||
import x.json2
|
||||
|
||||
struct SomeStruct {
|
||||
title string
|
||||
}
|
||||
|
||||
fn test_result_with_index() {
|
||||
resp := '{
|
||||
"userId": 1,
|
||||
"id": 1,
|
||||
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
|
||||
"body": "quia et suscipitsuscipit recusandae consequuntur expedita et cumreprehenderit molestiae ut ut quas totamnostrum rerum est autem sunt rem eveniet architecto"
|
||||
}'
|
||||
raw_data := json2.raw_decode(resp)!
|
||||
|
||||
data := raw_data as map[string]json2.Any
|
||||
|
||||
mut ss := map[int]SomeStruct{}
|
||||
s := SomeStruct{
|
||||
title: data['title']!.str()
|
||||
}
|
||||
ss[data['id']!.int()] = s
|
||||
t := ss[data['id']!.int()]
|
||||
assert t.title == 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit'
|
||||
}
|
Loading…
Reference in New Issue
Block a user