From 8d2567740b9fcb945df6876a7f5b81909abfc26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Fri, 6 Aug 2021 02:54:24 +0200 Subject: [PATCH] parser: make [..] work (#11064) --- vlib/v/parser/parser.v | 9 +++++++-- vlib/v/tests/array_test.v | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index ba75af9f07..6414ae73ee 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2208,7 +2208,12 @@ fn (mut p Parser) index_expr(left ast.Expr) ast.IndexExpr { has_low = false // [..end] p.next() - high := p.expr(0) + mut high := ast.empty_expr() + mut has_high := false + if p.tok.kind != .rsbr { + high = p.expr(0) + has_high = true + } pos := start_pos.extend(p.tok.position()) p.check(.rsbr) return ast.IndexExpr{ @@ -2217,7 +2222,7 @@ fn (mut p Parser) index_expr(left ast.Expr) ast.IndexExpr { index: ast.RangeExpr{ low: ast.empty_expr() high: high - has_high: true + has_high: has_high pos: pos } } diff --git a/vlib/v/tests/array_test.v b/vlib/v/tests/array_test.v index 5340fc46bf..d872ce384c 100644 --- a/vlib/v/tests/array_test.v +++ b/vlib/v/tests/array_test.v @@ -18,3 +18,10 @@ fn test_for_in_shared_array_named_array() { } } } + +fn test_fixed_array_to_dynamic_array() { + y := [1, 2, 3]! + mut x := y[..] + x << 4 + assert x.len == 4 +}