Bug 10179 – Tuple assignment should not cause "has no effect" error even if the length is zero
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-26T20:35:00Z
Last change time
2013-05-27T06:19:25Z
Keywords
pull
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2013-05-26T20:35:32Z
Currently zero-length tuple assignment would cause "has no effect" error.
struct S {}
void main()
{
S s;
static assert(s.tupleof.length == 0);
s.tupleof = s.tupleof; // error
}
This is basically not bad, but in generic code this behavior requires additional length check.
struct S(Types...)
{
Types field;
void set(S rhs)
{
//field = rhs.field;
// --> When Types.length == 0, "has no effect" error occurs.
// Workaround
static if (Types.length > 0) // additional check
field = rhs.field;
}
}
void main()
{
S!(int, long) s1;
s1.set(s1);
S!() s2;
s2.set(s2);
}
So I think that stop reporting "has no effect" error for tuple assignment is small but useful improvement.