mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
a38310f929
commit
0d6d6f7de8
@ -327,6 +327,17 @@ fn (mut g Gen) index_of_fixed_array(node ast.IndexExpr, sym ast.TypeSymbol) {
|
|||||||
elem_sym := g.table.sym(elem_type)
|
elem_sym := g.table.sym(elem_type)
|
||||||
is_fn_index_call := g.is_fn_index_call && elem_sym.info is ast.FnType
|
is_fn_index_call := g.is_fn_index_call && elem_sym.info is ast.FnType
|
||||||
|
|
||||||
|
if node.left is ast.ArrayInit {
|
||||||
|
tmp := g.new_tmp_var()
|
||||||
|
line := g.go_before_stmt(0).trim_space()
|
||||||
|
styp := g.typ(node.left_type)
|
||||||
|
g.empty_line = true
|
||||||
|
g.write('$styp $tmp = ')
|
||||||
|
g.expr(node.left)
|
||||||
|
g.writeln(';')
|
||||||
|
g.write(line)
|
||||||
|
g.write(tmp)
|
||||||
|
} else {
|
||||||
if is_fn_index_call {
|
if is_fn_index_call {
|
||||||
g.write('(*')
|
g.write('(*')
|
||||||
}
|
}
|
||||||
@ -337,6 +348,7 @@ fn (mut g Gen) index_of_fixed_array(node ast.IndexExpr, sym ast.TypeSymbol) {
|
|||||||
} else {
|
} else {
|
||||||
g.expr(node.left)
|
g.expr(node.left)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g.write('[')
|
g.write('[')
|
||||||
direct := unsafe { g.fn_decl != 0 } && g.fn_decl.is_direct_arr
|
direct := unsafe { g.fn_decl != 0 } && g.fn_decl.is_direct_arr
|
||||||
if (direct || node.index is ast.IntegerLiteral) || g.pref.translated {
|
if (direct || node.index is ast.IntegerLiteral) || g.pref.translated {
|
||||||
|
7
vlib/v/tests/fixed_array_literal_index_test.v
Normal file
7
vlib/v/tests/fixed_array_literal_index_test.v
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fn test_fixed_array_literal_index() {
|
||||||
|
println([1]int{}[0])
|
||||||
|
assert [1]int{}[0] == 0
|
||||||
|
|
||||||
|
println([1, 2]![1])
|
||||||
|
assert [1, 2]![1] == 2
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user