Bug 8815 – alias modification silently fails on nested fields
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-13T19:48:00Z
Last change time
2016-08-27T22:52:22Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2012-10-13T19:48:21Z
@property void modify(alias symb)()
{
symb = new int;
}
class Foo
{
this()
{
modify!(x);
modify!(c.x);
assert(x); // ok
assert(c.x); // fail, c.x. is null
}
static struct C { int* x; }
C c;
int* x;
}
void main()
{
auto foo = new Foo;
}
Comment #1 by andrej.mitrovich — 2012-10-13T19:59:26Z
But I'm beginning to think using aliases like this isn't the best choice. For one thing it won't work if the alias is a private symbol. It's probably best to use templated functions that take a 'ref' parameter.
Comment #2 by andrej.mitrovich — 2013-01-26T14:05:49Z
I can see why, it seems "c.x" gets converted to "this.x":
@property void init(alias symb)()
{
pragma(msg, symb); // "this.x", should be "s.x"
symb = new int;
}
class C
{
this()
{
init!(s.x);
}
struct S { int* x; }
S s;
}
void main()
{
auto c = new C;
}
Additionally I get this in this sample:
core.exception.InvalidMemoryOperationError
Comment #3 by andrej.mitrovich — 2016-08-27T22:52:22Z
Can't pass instance fields as alias parameters, this is a known limitation and part of other enhancement requests.