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

parser: fix fn argument type position (#15102)

This commit is contained in:
yuyi 2022-07-17 15:55:20 +08:00 committed by GitHub
parent 3075e35237
commit 78242627c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 9 deletions

View File

@ -2,6 +2,6 @@ vlib/v/checker/tests/array_sort_with_compare_ref_elem_err.vv:21:23: error: sort_
19 | }
20 |
21 | fn sort_cells_by_yx(a &Cell, b &Cell) int {
| ^
| ~~~~~
22 | if a.pos.y == b.pos.y {
23 | if a.pos.x < b.pos.x {

View File

@ -1,5 +1,5 @@
vlib/v/checker/tests/fn_arg_of_optional_err.vv:1:19: error: optional type argument is not supported currently
1 | fn optional_arg(x ?int) {
| ^
| ~~~~
2 | println('int type: $x')
3 | }

View File

@ -1,26 +1,26 @@
vlib/sokol/audio/audio.v:86:26: error: struct `C.saudio_desc` was declared as private to module `module_with_redeclaration`, so it can not be used inside module `sokol.audio`
84 | fn C.saudio_userdata() voidptr
85 |
85 |
86 | fn C.saudio_query_desc() C.saudio_desc
| ~~~~~~~~~~~~~
87 |
87 |
88 | fn C.saudio_sample_rate() int
vlib/sokol/audio/audio.v:101:19: error: struct `C.saudio_desc` was declared as private to module `module_with_redeclaration`, so it can not be used inside module `sokol.audio`
99 |
99 |
100 | // setup - setup sokol-audio
101 | pub fn setup(desc &C.saudio_desc) {
| ^
| ~~~~~~~~~~~~~~
102 | C.saudio_setup(desc)
103 | }
vlib/sokol/audio/audio.v:121:16: error: struct `C.saudio_desc` was declared as private to module `module_with_redeclaration`, so it can not be used inside module `sokol.audio`
119 |
119 |
120 | // query - return a copy of the original saudio_desc struct
121 | pub fn query() C.saudio_desc {
| ~~~~~~~~~~~~~
122 | return C.saudio_query_desc()
123 | }
vlib/v/checker/tests/private_redeclaration_of_C_struct.vv:7:10: error: struct `C.saudio_desc` was declared as private to module `module_with_redeclaration`, so it can not be used inside module `main`
5 |
5 |
6 | fn main() {
7 | sd := C.saudio_desc{}
| ~~~~~~~~~~~~~

View File

@ -830,6 +830,7 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
}
pos := p.tok.pos()
mut arg_type := p.parse_type()
type_pos := pos.extend(p.prev_tok.pos())
if arg_type == 0 {
// error is added in parse_type
return []ast.Param{}, false, false
@ -884,7 +885,7 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
name: name
is_mut: is_mut
typ: arg_type
type_pos: pos
type_pos: type_pos
}
arg_no++
if arg_no > 1024 {
@ -940,6 +941,7 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
}
pos := p.tok.pos()
mut typ := p.parse_type()
type_pos[0] = pos.extend(p.prev_tok.pos())
if typ == 0 {
// error is added in parse_type
return []ast.Param{}, false, false