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

parser: fix position of array init (#6998)

This commit is contained in:
Daniel Däschle 2020-11-28 16:05:14 +01:00 committed by GitHub
parent ea04d23e1d
commit 6e4dad9acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 9 deletions

View File

@ -1072,9 +1072,6 @@ pub fn (expr Expr) position() token.Position {
InfixExpr {
left_pos := expr.left.position()
right_pos := expr.right.position()
if left_pos.pos == 0 || right_pos.pos == 0 {
return expr.pos
}
return token.Position{
line_nr: expr.pos.line_nr
pos: left_pos.pos

View File

@ -5,7 +5,6 @@ module parser
import v.ast
import v.table
import v.token
fn (mut p Parser) array_init() ast.ArrayInit {
first_pos := p.tok.position()
@ -23,6 +22,7 @@ fn (mut p Parser) array_init() ast.ArrayInit {
mut has_default := false
mut default_expr := ast.Expr{}
if p.tok.kind == .rsbr {
last_pos = p.tok.position()
// []typ => `[]` and `typ` must be on the same line
line_nr := p.tok.line_nr
p.next()
@ -126,11 +126,7 @@ fn (mut p Parser) array_init() ast.ArrayInit {
}
p.check(.rcbr)
}
pos := token.Position{
line_nr: first_pos.line_nr
pos: first_pos.pos
len: last_pos.pos - first_pos.pos + last_pos.len
}
pos := first_pos.extend(last_pos)
return ast.ArrayInit{
is_fixed: is_fixed
has_val: has_val

View File

@ -0,0 +1,5 @@
vlib/v/parser/tests/array_pos_err.vv:2:2: error: expression evaluated but not used
1 | fn main() {
2 | '' in []
| ~~~~~~~~
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
'' in []
}