-
-
Notifications
You must be signed in to change notification settings - Fork 369
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
Clarify spec for "+=" and friends #1429
base: master
Are you sure you want to change the base?
Conversation
See https://forum.dlang.org/post/mxvdieydnicvdxbcklrd@forum.dlang.org (submitted through the website and I cannot make changes to this PR. Because I am cleaning up after people, if you don't like it, please submit your own PR.)
Is you "you don't want to" or you technically can't? Editing a PR made from the website is easy:
or if you already have it, update its remote info:
and then go into the usual flow:
|
assert(sum == 8); // "eight" ! | ||
|
||
sum = 0; | ||
sum = cast(typeof(sum))(sum + add7tosum_return1()); |
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.
Why is the cast necessary?
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 isn't. But I made it look exactly the same as the given "semantic equivalent" above.
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 is necessary if all isn't int.
This needs to be extended with semantics for operations on arrays, like int work(ref int[] array) {
array ~= 5;
return 0;
}
void doTildeAssignment(T)(ref T[] x, T y) {
x = x ~ y;
}
void main(){
int[] array;
version(none) {
array ~= work(array);
} else {
doTildeAssignment(array, work(array));
}
assert(array == [5,0]);
} |
See https://forum.dlang.org/post/mxvdieydnicvdxbcklrd@forum.dlang.org
(submitted through the website and I cannot make changes to this PR. Because I am cleaning up after people, if you don't like it, please submit your own PR.)