Skip to content

Commit

Permalink
imporve error position
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Apr 5, 2024
1 parent e034cbc commit 08c02a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions vlib/v/checker/struct.v
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,13 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
} else {
parts.last()
}
c.error('cannot access private field `${field.name}` on `${mod_type}`',
node.pos)
for init_field in node.init_fields {
if field.name == init_field.name {
c.error('cannot access private field `${field.name}` on `${mod_type}`',
init_field.pos)
break
}
}
}
if field.is_deprecated {
for init_field in node.init_fields {
Expand Down
8 changes: 4 additions & 4 deletions vlib/v/checker/tests/struct_field_private_err.out
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
vlib/v/checker/tests/struct_field_private_err.vv:7:11: error: cannot access private field `x` on `amod.Bcg`
5 | }
vlib/v/checker/tests/struct_field_private_err.vv:8:2: error: cannot access private field `x` on `amod.Bcg`
6 |
7 | _ := amod.Bcg{
| ~~~~
8 | x: 0
| ~~~~
9 | }
10 |
vlib/v/checker/tests/struct_field_private_err.vv:11:10: error: cannot access private field `bar` on `amod.FooParams`
9 | }
10 |
11 | amod.foo(bar: 'bar')
| ~~~~~~~~~~~
| ~~~~~~~~~~

0 comments on commit 08c02a9

Please sign in to comment.