diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 13eb3c6e20..76a72b6201 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -152,8 +152,10 @@ pub fn (mut p Parser) parse_type() table.Type { if p.tok.kind == .mul { p.error('use `&Type` instead of `*Type` when declaring references') } + mut nr_amps := 0 // &Type for p.tok.kind == .amp { + nr_amps++ nr_muls++ p.next() } @@ -178,7 +180,7 @@ pub fn (mut p Parser) parse_type() table.Type { } if nr_muls > 0 { typ = typ.set_nr_muls(nr_muls) - if is_array { + if is_array && nr_amps > 0 { p.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) {}`.')