mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
a38310f929
commit
0d6d6f7de8
@ -327,15 +327,27 @@ fn (mut g Gen) index_of_fixed_array(node ast.IndexExpr, sym ast.TypeSymbol) {
|
||||
elem_sym := g.table.sym(elem_type)
|
||||
is_fn_index_call := g.is_fn_index_call && elem_sym.info is ast.FnType
|
||||
|
||||
if is_fn_index_call {
|
||||
g.write('(*')
|
||||
}
|
||||
if node.left_type.is_ptr() {
|
||||
g.write('(*')
|
||||
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.write(')')
|
||||
g.writeln(';')
|
||||
g.write(line)
|
||||
g.write(tmp)
|
||||
} else {
|
||||
g.expr(node.left)
|
||||
if is_fn_index_call {
|
||||
g.write('(*')
|
||||
}
|
||||
if node.left_type.is_ptr() {
|
||||
g.write('(*')
|
||||
g.expr(node.left)
|
||||
g.write(')')
|
||||
} else {
|
||||
g.expr(node.left)
|
||||
}
|
||||
}
|
||||
g.write('[')
|
||||
direct := unsafe { g.fn_decl != 0 } && g.fn_decl.is_direct_arr
|
||||
|
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