mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix array of alias's slice() (#10772)
This commit is contained in:
parent
b09fa69cb3
commit
1b26ce1f7a
@ -58,7 +58,7 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
|
||||
}
|
||||
|
||||
fn (mut g Gen) range_expr(node ast.IndexExpr, range ast.RangeExpr) {
|
||||
sym := g.table.get_type_symbol(node.left_type)
|
||||
sym := g.table.get_final_type_symbol(node.left_type)
|
||||
if sym.kind == .string {
|
||||
g.write('string_substr(')
|
||||
g.expr(node.left)
|
||||
|
12
vlib/v/tests/array_of_alias_slice_test.v
Normal file
12
vlib/v/tests/array_of_alias_slice_test.v
Normal file
@ -0,0 +1,12 @@
|
||||
type Ints = []int
|
||||
|
||||
fn (i Ints) slice(to int) Ints {
|
||||
return i[0..to]
|
||||
}
|
||||
|
||||
fn test_array_of_alias_slice() {
|
||||
values := Ints([5, 7, 9])
|
||||
|
||||
println(values.slice(2))
|
||||
assert values.slice(2) == Ints([5, 7])
|
||||
}
|
Loading…
Reference in New Issue
Block a user