mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
e72d259903
commit
1ac3f3d8dc
@ -431,8 +431,8 @@ pub fn (mut p Parser) parse_type() ast.Type {
|
|||||||
language := p.parse_language()
|
language := p.parse_language()
|
||||||
mut typ := ast.void_type
|
mut typ := ast.void_type
|
||||||
is_array := p.tok.kind == .lsbr
|
is_array := p.tok.kind == .lsbr
|
||||||
if p.tok.kind != .lcbr {
|
|
||||||
pos := p.tok.pos()
|
pos := p.tok.pos()
|
||||||
|
if p.tok.kind != .lcbr {
|
||||||
typ = p.parse_any_type(language, nr_muls > 0, true)
|
typ = p.parse_any_type(language, nr_muls > 0, true)
|
||||||
if typ.idx() == 0 {
|
if typ.idx() == 0 {
|
||||||
// error is set in parse_type
|
// error is set in parse_type
|
||||||
@ -462,9 +462,10 @@ pub fn (mut p Parser) parse_type() ast.Type {
|
|||||||
if nr_muls > 0 {
|
if nr_muls > 0 {
|
||||||
typ = typ.set_nr_muls(nr_muls)
|
typ = typ.set_nr_muls(nr_muls)
|
||||||
if is_array && nr_amps > 0 {
|
if is_array && nr_amps > 0 {
|
||||||
p.error('V arrays are already references behind the scenes,
|
p.error_with_pos('V arrays are already references behind the scenes,
|
||||||
there is no need to use a reference to an array (e.g. use `[]string` instead of `&[]string`).
|
there is no need to use a reference to an array (e.g. use `[]string` instead of `&[]string`).
|
||||||
If you need to modify an array in a function, use a mutable argument instead: `fn foo(mut s []string) {}`.')
|
If you need to modify an array in a function, use a mutable argument instead: `fn foo(mut s []string) {}`.',
|
||||||
|
pos)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
vlib/v/parser/tests/ref_array_pos_err.out
Normal file
8
vlib/v/parser/tests/ref_array_pos_err.out
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
vlib/v/parser/tests/ref_array_pos_err.vv:2:5: error: V arrays are already references behind the scenes,
|
||||||
|
there is no need to use a reference to an array (e.g. use `[]string` instead of `&[]string`).
|
||||||
|
If you need to modify an array in a function, use a mutable argument instead: `fn foo(mut s []string) {}`.
|
||||||
|
1 | struct Foo {
|
||||||
|
2 | b &[]u8
|
||||||
|
| ^
|
||||||
|
3 | n int
|
||||||
|
4 | }
|
4
vlib/v/parser/tests/ref_array_pos_err.vv
Normal file
4
vlib/v/parser/tests/ref_array_pos_err.vv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
struct Foo {
|
||||||
|
b &[]u8
|
||||||
|
n int
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user