mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: improve the position of mut receiver warning / error (#8240)
This commit is contained in:
parent
925ffd76f4
commit
1b09954622
14
vlib/v/checker/tests/mut_receiver.out
Normal file
14
vlib/v/checker/tests/mut_receiver.out
Normal file
@ -0,0 +1,14 @@
|
||||
vlib/v/checker/tests/mut_receiver.vv:5:4: warning: use `(mut f Foo)` instead of `(f mut Foo)`
|
||||
3 | name string
|
||||
4 | }
|
||||
5 | fn (f mut Foo) info() {
|
||||
| ~~~~~~~~~~~
|
||||
6 | f.name = 'foo'
|
||||
7 | }
|
||||
vlib/v/checker/tests/mut_receiver.vv:8:4: error: use `(mut f Foo)` or `(f &Foo)` instead of `(mut f &Foo)`
|
||||
6 | f.name = 'foo'
|
||||
7 | }
|
||||
8 | fn (mut f &Foo) info2() {
|
||||
| ~~~~~~~~~~~~
|
||||
9 | f.name = 'foo'
|
||||
10 | }
|
@ -5,6 +5,9 @@ mut:
|
||||
fn (f mut Foo) info() {
|
||||
f.name = 'foo'
|
||||
}
|
||||
fn (mut f &Foo) info2() {
|
||||
f.name = 'foo'
|
||||
}
|
||||
fn main() {
|
||||
println('hello, world')
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
vlib/v/checker/tests/mut_receiver_warning.vv:5:7: warning: use `(mut f Foo)` instead of `(f mut Foo)`
|
||||
3 | name string
|
||||
4 | }
|
||||
5 | fn (f mut Foo) info() {
|
||||
| ~~~
|
||||
6 | f.name = 'foo'
|
||||
7 | }
|
@ -195,6 +195,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||
mut rec_mut := false
|
||||
mut params := []table.Param{}
|
||||
if p.tok.kind == .lpar {
|
||||
lpar_pos := p.tok.position()
|
||||
p.next() // (
|
||||
is_method = true
|
||||
is_shared := p.tok.kind == .key_shared
|
||||
@ -208,7 +209,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||
if !rec_mut {
|
||||
rec_mut = p.tok.kind == .key_mut
|
||||
if rec_mut {
|
||||
p.warn_with_pos('use `(mut f Foo)` instead of `(f mut Foo)`', p.tok.position())
|
||||
p.warn_with_pos('use `(mut f Foo)` instead of `(f mut Foo)`', lpar_pos.extend(p.peek_tok2.position()))
|
||||
}
|
||||
}
|
||||
receiver_pos = rec_start_pos.extend(p.tok.position())
|
||||
@ -231,7 +232,8 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||
}
|
||||
rec_type_pos = rec_type_pos.extend(p.prev_tok.position())
|
||||
if is_amp && rec_mut {
|
||||
p.error('use `(mut f Foo)` or `(f &Foo)` instead of `(mut f &Foo)`')
|
||||
p.error_with_pos('use `(mut f Foo)` or `(f &Foo)` instead of `(mut f &Foo)`',
|
||||
lpar_pos.extend(p.tok.position()))
|
||||
return ast.FnDecl{
|
||||
scope: 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user