mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
parser: add better error for mut variadic fn argument (#21063)
This commit is contained in:
parent
8b7f9089f6
commit
44c78ed761
5 changed files with 20 additions and 0 deletions
|
@ -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 {
|
||||||
|
|
3
vlib/v/parser/tests/fn_alias_arg_variadic_mut_err.out
Normal file
3
vlib/v/parser/tests/fn_alias_arg_variadic_mut_err.out
Normal 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)
|
||||||
|
| ~~~~~~
|
1
vlib/v/parser/tests/fn_alias_arg_variadic_mut_err.vv
Normal file
1
vlib/v/parser/tests/fn_alias_arg_variadic_mut_err.vv
Normal file
|
@ -0,0 +1 @@
|
||||||
|
type Foo = fn(mut ...string)
|
5
vlib/v/parser/tests/fn_arg_variadic_mut_err.out
Normal file
5
vlib/v/parser/tests/fn_arg_variadic_mut_err.out
Normal 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 | }
|
3
vlib/v/parser/tests/fn_arg_variadic_mut_err.vv
Normal file
3
vlib/v/parser/tests/fn_arg_variadic_mut_err.vv
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn load(mut filepaths ...string) {
|
||||||
|
println(filepaths[0])
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue