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:
parent
ea04d23e1d
commit
6e4dad9acf
@ -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
|
||||
|
@ -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
|
||||
|
5
vlib/v/parser/tests/array_pos_err.out
Normal file
5
vlib/v/parser/tests/array_pos_err.out
Normal 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 | }
|
3
vlib/v/parser/tests/array_pos_err.vv
Normal file
3
vlib/v/parser/tests/array_pos_err.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
'' in []
|
||||
}
|
Loading…
Reference in New Issue
Block a user