dlang.org icon indicating copy to clipboard operation
dlang.org copied to clipboard

Clarify spec for "+=" and friends

Open JohanEngelen opened this issue 7 years ago • 2 comments

See https://forum.dlang.org/post/[email protected]

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

JohanEngelen avatar Jul 12 '16 09:07 JohanEngelen

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 [email protected]/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

wilzbach avatar Jul 12 '16 11:07 wilzbach

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 https://github.com/ldc-developers/ldc/issues/2588

JohanEngelen avatar Feb 20 '18 17:02 JohanEngelen