-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
checker: disallow structs with @[params]
attribute as mutable function parameters
#21206
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
87e877f
fix
ttytm 28a7e51
test
ttytm 67be7e6
Revert "test"
ttytm 458c836
Revert "fix"
ttytm b73c8d7
disallow mut params struct in fn_decl
ttytm bc6830c
add error test
ttytm 22300ee
remove test that used mut params struct as regular struct
ttytm e50ec29
make sure there is a test that tests mutable struct parameter
ttytm 8ecdda2
rm eventually unused
ttytm File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vlib/v/checker/tests/mut_parms_struct_param_err.vv:8:17: error: declaring a mutable parameter that accepts a struct with the `@[params]` attribute is not allowed | ||
6 | } | ||
7 | | ||
8 | fn foo(mut opts Params) bool { | ||
| ~~~~~~ | ||
9 | return opts.a | ||
10 | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@[params] | ||
struct Params { | ||
mut: | ||
a bool | ||
x int | ||
} | ||
|
||
fn foo(mut opts Params) bool { | ||
return opts.a | ||
} | ||
|
||
foo(a: true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remain to be allowed, the call has
mut c_
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inconsistency, is only when you use the default
f()
, and f gets a mutable parameter, that was created implicitly. If you pass it explicitly, you and the reader will know where it originated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test used
Config
(a struct with a@[params]
attribute) to test passing mutable structs. That's why I added another test passing a mut struct that isn't a params struct.Else wouldn't this disagree with alex, disallowing mut params, and lead us where I wanted to go in the second comment? Allowing a params struct like this:
Or is what is meant to be done here to only disallow trailing mut params structs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know. @medvednikov what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a params struct, so it makes sense that the new
mut
rule is applied to it as well.It's fine.
Thanks, great job.