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