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
Conversation
I am not sure if that should work. @medvednikov what do you think? |
Looking into it again. It should not work at that point. So, if a mutable params struct should be allowed after all, the second example below should trigger an error that the arg would have to be passed as part of a mutable struct. foo() // should work with a mutable params struct?
foo(a: true) // with the PR it doesn't error if the args param is mutable
mut p := Params{a: true} // Should required when deciding o pass a mutable params struct?
foo(mut p) |
@spytheman I agree, I think mutable params simply shouldn't be allowed. |
072be13
to
bc6830c
Compare
Okay, I updated the PR to disallow it when declaring a fn with it. But I don't fully see through where it would cause problems. Why not allowing it to be handled like any other mutable struct and to be optional? |
@[params]
attribute as mutable function parameters
For normal non If you allow That can be valuable, but also inconsistent. -> I can see it both ways, thus I could not decide how it should behave. |
(without testing if it was optional)
mut c_ := Config{ | ||
def: 10 | ||
} | ||
c := mut_bar_config(mut c_, 10) |
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 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.
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:
mut p := Params{a: true} foo(mut p)
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.
@[params]
struct Config {}
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.
Fixes #21205