-
-
Notifications
You must be signed in to change notification settings - Fork 657
Disallow assigning to struct rvalue #21717
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request and interest in making D better, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.
|
e36b3b6 to
61ce191
Compare
This comment was marked as outdated.
This comment was marked as outdated.
aa52efa to
05f17a1
Compare
compiler/src/dmd/expressionsem.d
Outdated
| if (!sc.intypeof && exp.e1.type.ty == Tstruct && !exp.e1.isLvalue()) | ||
| { | ||
| error(exp.e1.loc, "cannot modify struct rvalue `%s`", |
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.
What other rvalues could appear here? Does it make sense to only restrict 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.
The check in opOverloadBinaryAssign would get hit by:
int[] a;
a.length += 1;It would also get hit for a class C (new C) += 4;. That should be prevented too, but I don't want to do that in this pull.
|
rvalues cannot be assigned to by definition, correct? |
|
I snipped the buildkite failures below. The libdparse one is fixed upstream. The other projects are failing due to one of these dependency failures. |
Currently dmd allows it for a struct overloading assignment. |
When assignment would call an operator overload.
Fixes #21507.
Note: This does not disallow calling e.g.
opAssignon an rvalue, only actual assignment.