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

Clarify spec for "+=" and friends #1429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JohanEngelen
Copy link
Contributor

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.)

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.)
@wilzbach
Copy link
Member

submitted through the website and I cannot make changes to this PR.

Is you "you don't want to" or you technically can't? Editing a PR made from the website is easy:
If you don't have the repo locally, clone it:

git clone git@github.com/JohanEngelen/dlang.org

or if you already have it, update its remote info:

git fetch 

and then go into the usual flow:

git checkout patch-5
// make changes & commit
git push -f

assert(sum == 8); // "eight" !

sum = 0;
sum = cast(typeof(sum))(sum + add7tosum_return1());
Copy link
Member

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?

Copy link
Contributor Author

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.

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.

@JohanEngelen
Copy link
Contributor Author

This needs to be extended with semantics for operations on arrays, like ~= (for which the types of lhs and rhs are not the same, T[] vs T).

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 ldc-developers/ldc#2588

@JinShil JinShil added the Vision https://wiki.dlang.org/Vision/2018H1 label Mar 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants