From 1b26ce1f7a3920bfa07a54f32545d42a9d22127e Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 12 Jul 2021 20:59:01 +0800 Subject: [PATCH] cgen: fix array of alias's slice() (#10772) --- vlib/v/gen/c/index.v | 2 +- vlib/v/tests/array_of_alias_slice_test.v | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/array_of_alias_slice_test.v diff --git a/vlib/v/gen/c/index.v b/vlib/v/gen/c/index.v index d7cb79c32f..c2b22d5c72 100644 --- a/vlib/v/gen/c/index.v +++ b/vlib/v/gen/c/index.v @@ -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) diff --git a/vlib/v/tests/array_of_alias_slice_test.v b/vlib/v/tests/array_of_alias_slice_test.v new file mode 100644 index 0000000000..d5f2716e97 --- /dev/null +++ b/vlib/v/tests/array_of_alias_slice_test.v @@ -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]) +}