Bug 2811 – mixin fields not visible inside mixin method
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-04-06T10:42:00Z
Last change time
2015-06-09T01:18:03Z
Assigned to
bugzilla
Creator
2korden
Comments
Comment #0 by 2korden — 2009-04-06T10:42:38Z
Let's start with code I'd like to write:
struct Own(T)
{
void opAssign(ref Own other)
{
_ptr = other._ptr;
other._ptr = null;
}
private T _ptr = null;
}
I'm trying to use it like this:
alias Own!(Resource) ResourcePtr;
but it causes template forward referencing all the time.
So my next step is to workaround this issue:
class Resource {}
struct OwnT(T, Own)
{
void opAssign(ref Own other)
{
_ptr = other._ptr;
other._ptr = null;
}
protected T _ptr = null;
}
struct ResourcePtr
{
mixin OwnT!(Resource, ResourcePtr);
}
But I'm getting the following errors:
test.d(7): Error: no property '_ptr' for type 'ResourcePtr'
test.d(7): Error: cannot implicitly convert expression (1) of type int to test.Resource
test.d(7): Error: cannot cast int to test.Resource
test.d(8): Error: no property '_ptr' for type 'ResourcePtr'
test.d(8): Error: constant other._ptr is not an lvalue
test.d(8): Error: cannot implicitly convert expression (null) of type void* to int
Comment #1 by 2korden — 2009-04-06T10:45:59Z
Nvm, it looks like I mistakenly was trying to mixin struct template, not mixin template.
template OwnT(T, Own)
{
// ...
}
Would fix the issue.
On the other, is this supposed to work? If it's not, perhaps error message could state "can not mixin struct" instead. (Shall I post it as an enhancement request?)