Bug 13623 – std.typecons.Proxy doesn't work inside classes
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-10-16T22:37:00Z
Last change time
2014-11-27T14:38:53Z
Keywords
pull
Assigned to
nobody
Creator
code
Comments
Comment #0 by code — 2014-10-16T22:37:31Z
cat > bug.d << CODE
import std.typecons, std.traits;
class Foo
{
private int value;
mixin Proxy!value;
this(int n){ value = n; }
}
unittest
{
auto a = new Foo(10), b = new Foo(10);
assert(a == b); // Proxy should override Object.opEquals
a = 13;
}
CODE
dmd -unittest -main -run bug
----
I think it's reasonable for Proxy to only work inside structs, but there should be a check in the mixin template.
static assert(!is(typeof(this) == class), "Proxy cannot be used inside classes.");
Comment #1 by dev — 2014-10-17T17:04:33Z
What is the rationale for stopping Proxy working with classes? Although i don't have any real use cases, surely it would be better just to fix it to work with classes?