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

parser: correct error position on field and method errors

This commit is contained in:
Daniel Däschle 2020-04-12 14:19:07 +02:00 committed by GitHub
parent e247690fe1
commit 4449468ca4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 2 deletions

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/inout/unknown_field.v:7:12: error: unknown field `checker.Test.sdd`
5| fn main() {
6| t := Test{}
7| println(t.sdd)
~~~
8| }

View File

@ -0,0 +1,8 @@
module checker
struct Test {}
fn main() {
t := Test{}
println(t.sdd)
}

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/inout/unknown_method.v:7:12: error: unknown method: checker.Test.sdd
5| fn main() {
6| t := Test{}
7| println(t.sdd())
~~~~~
8| }

View File

@ -0,0 +1,8 @@
module checker
struct Test {}
fn main() {
t := Test{}
println(t.sdd())
}

View File

@ -953,17 +953,18 @@ fn (p mut Parser) filter() {
fn (p mut Parser) dot_expr(left ast.Expr) ast.Expr {
p.next()
mut name_pos := p.tok.position()
field_name := p.check_name()
is_filter := field_name in ['filter', 'map']
if is_filter {
p.open_scope()
name_pos = p.tok.position()
p.filter()
// wrong tok position when using defer
// defer {
// p.close_scope()
// }
}
pos := p.tok.position()
// Method call
if p.tok.kind == .lpar {
p.next()
@ -986,6 +987,12 @@ fn (p mut Parser) dot_expr(left ast.Expr) ast.Expr {
or_stmts = p.parse_block_no_scope()
p.close_scope()
}
end_pos := p.tok.position()
pos := token.Position{
line_nr: name_pos.line_nr
pos: name_pos.pos
len: end_pos.pos - name_pos.pos
}
mcall_expr := ast.CallExpr{
left: left
name: field_name
@ -1007,7 +1014,7 @@ fn (p mut Parser) dot_expr(left ast.Expr) ast.Expr {
sel_expr := ast.SelectorExpr{
expr: left
field: field_name
pos: p.tok.position()
pos: name_pos
}
mut node := ast.Expr{}
node = sel_expr