Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 19, 2024

Conversation

Delta456
Copy link
Member

Code snippet:

fn load(mut filepaths ...string) {
	println(filepaths[0])
}

Before:

(before this PR)

file.v:1:26: error: mutable arguments are only allowed for arrays, interfaces, maps, pointers, structs or their aliases
return values instead: `fn foo(mut n string) {` => `fn foo(n string) string {`
    1 | fn load(mut filepaths ...string) {
      |                          ~~~~~~
    2 |     println(filepaths[0])
    3 | }

After:

(after this PR)

file.v:1:26: error: variadic arguments cannot be `mut`, `shared` or `atomic`
    1 | fn load(mut filepaths ...string) {
      |                          ~~~~~~
    2 |     println(filepaths[0])
    3 | }

@Delta456 Delta456 changed the title parser: add better error for variadic fn argument parser: add better error for mut variadic fn argument Mar 19, 2024
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit 44c78ed into vlang:master Mar 19, 2024
54 checks passed
@Delta456 Delta456 deleted the fn_arg_variadic_mut_err branch March 20, 2024 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants