1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: make [..] work (#11064)

This commit is contained in:
Daniel Däschle 2021-08-06 02:54:24 +02:00 committed by GitHub
parent c30cda3daf
commit 8d2567740b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

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

View File

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