www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2811] New: mixin fields not visible inside mixin method

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2811

           Summary: mixin fields not visible inside mixin method
           Product: D
           Version: 2.027
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: 2korden gmail.com


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


-- 
Apr 06 2009
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2811


2korden gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from 2korden gmail.com  2009-04-06 10:45 -------
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?)


-- 
Apr 06 2009