cgen: fix array of alias's slice() (#10772)

pull/10784/head
yuyi 2021-07-12 20:59:01 +08:00 committed by GitHub
parent b09fa69cb3
commit 1b26ce1f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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)

View 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])
}