mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix fixed array literal range index (#16812)
This commit is contained in:
parent
c10bc09e83
commit
15c9153f1d
@ -120,8 +120,20 @@ fn (mut g Gen) index_range_expr(node ast.IndexExpr, range ast.RangeExpr) {
|
||||
if node.left_type.is_ptr() {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr(node.left)
|
||||
g.write(')')
|
||||
if node.left is ast.ArrayInit {
|
||||
var := 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} ${var} = ')
|
||||
g.expr(node.left)
|
||||
g.writeln(';')
|
||||
g.write(line)
|
||||
g.write(' ${var})')
|
||||
} else {
|
||||
g.expr(node.left)
|
||||
g.write(')')
|
||||
}
|
||||
} else {
|
||||
g.expr(node.left)
|
||||
}
|
||||
|
7
vlib/v/tests/fixed_array_literal_range_index_test.v
Normal file
7
vlib/v/tests/fixed_array_literal_range_index_test.v
Normal file
@ -0,0 +1,7 @@
|
||||
fn test_fixed_array_literal_range_index() {
|
||||
arr := [1, 2, 3, 4]![..]
|
||||
println(arr)
|
||||
println(typeof(arr).name)
|
||||
assert typeof(arr).name == '[]int'
|
||||
assert '${arr}' == '[1, 2, 3, 4]'
|
||||
}
|
Loading…
Reference in New Issue
Block a user