Bug 15026 – cannot array assign to a slice return value

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-08T01:34:41Z
Last change time
2024-12-13T18:44:39Z
Assigned to
No Owner
Creator
Martin Nowak
Moved to GitHub: dmd#19040 →

Comments

Comment #0 by code — 2015-09-08T01:34:41Z
cat > bug.d << CODE int[] bar() { return null; } void test() { bar() = 2; } CODE ---- Error: bar() is not an lvalue ---- Even more annoying with opSlice. cat > bug.d << CODE struct Foo { int[] opSlice() { return null; } } void test() { Foo foo; foo[] = 2; } CODE ---- Error: foo[] is not an lvalue ---- Seems like the lvalue check should be done after array assignments are lowered.
Comment #1 by code — 2015-09-08T01:35:34Z
Workaround is to slice the return value, i.e. `bar()[]` and `foo[][]`.
Comment #2 by cauterite — 2015-09-12T07:02:49Z
The first example doesn't look to me like it should compile. Is it not equivalent to this? void test() { (cast(int[]) null) = 2; } The second example works if you use opIndexAssign instead of opSlice: struct Foo { int[] opIndexAssign(int v) { return null; } } void test() { Foo foo; foo[] = 2; }
Comment #3 by robert.schadek — 2024-12-13T18:44:39Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19040 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB