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:
parent
e247690fe1
commit
4449468ca4
6
vlib/v/checker/tests/inout/unknown_field.out
Normal file
6
vlib/v/checker/tests/inout/unknown_field.out
Normal 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| }
|
8
vlib/v/checker/tests/inout/unknown_field.vv
Normal file
8
vlib/v/checker/tests/inout/unknown_field.vv
Normal file
@ -0,0 +1,8 @@
|
||||
module checker
|
||||
|
||||
struct Test {}
|
||||
|
||||
fn main() {
|
||||
t := Test{}
|
||||
println(t.sdd)
|
||||
}
|
6
vlib/v/checker/tests/inout/unknown_method.out
Normal file
6
vlib/v/checker/tests/inout/unknown_method.out
Normal 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| }
|
8
vlib/v/checker/tests/inout/unknown_method.vv
Normal file
8
vlib/v/checker/tests/inout/unknown_method.vv
Normal file
@ -0,0 +1,8 @@
|
||||
module checker
|
||||
|
||||
struct Test {}
|
||||
|
||||
fn main() {
|
||||
t := Test{}
|
||||
println(t.sdd())
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user