parser: add better error for mut variadic fn argument (#21063)

This commit is contained in:
Swastik Baranwal 2024-03-20 01:12:37 +05:30 committed by GitHub
parent 8b7f9089f6
commit 44c78ed761
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 0 deletions

View file

@ -912,6 +912,10 @@ fn (mut p Parser) fn_params() ([]ast.Param, bool, bool) {
} }
if is_mut { if is_mut {
if !param_type.has_flag(.generic) { if !param_type.has_flag(.generic) {
if is_variadic {
p.error_with_pos('variadic arguments cannot be `mut`, `shared` or `atomic`',
pos)
}
if is_shared { if is_shared {
p.check_fn_shared_arguments(param_type, pos) p.check_fn_shared_arguments(param_type, pos)
} else if is_atomic { } else if is_atomic {
@ -1027,6 +1031,10 @@ fn (mut p Parser) fn_params() ([]ast.Param, bool, bool) {
} }
if is_mut { if is_mut {
if !typ.has_flag(.generic) { if !typ.has_flag(.generic) {
if is_variadic {
p.error_with_pos('variadic arguments cannot be `mut`, `shared` or `atomic`',
pos)
}
if is_shared { if is_shared {
p.check_fn_shared_arguments(typ, pos) p.check_fn_shared_arguments(typ, pos)
} else if is_atomic { } else if is_atomic {

View file

@ -0,0 +1,3 @@
vlib/v/parser/tests/fn_alias_arg_variadic_mut_err.vv:1:22: error: variadic arguments cannot be `mut`, `shared` or `atomic`
1 | type Foo = fn(mut ...string)
| ~~~~~~

View file

@ -0,0 +1 @@
type Foo = fn(mut ...string)

View file

@ -0,0 +1,5 @@
vlib/v/parser/tests/fn_arg_variadic_mut_err.vv:1:26: error: variadic arguments cannot be `mut`, `shared` or `atomic`
1 | fn load(mut filepaths ...string) {
| ~~~~~~
2 | println(filepaths[0])
3 | }

View file

@ -0,0 +1,3 @@
fn load(mut filepaths ...string) {
println(filepaths[0])
}