www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6776] New: attributes injected via pure template mixin but not class mixin

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

           Summary: attributes injected via pure template mixin but not
                    class mixin
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dlang chilon.net



import std.stdio;

    class C(T) {
        T val;
    }

    class D {
        mixin C!bool;
    }

    int main() {
        auto d = new D;
        writeln(d.val);
        return 0;
    }

This fails to compile (no val in D), yet if defining C as:

    template C(T) {
        T val;
    }

It works.

This is rather silly as it forces me to write wrapper classes that forward to a
template.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 06 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6776


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |smjg iname.com
         Resolution|                            |INVALID



There's no such thing as a class mixin.  One mixes in template instances, not
classes.  Since a class template is just syntactic sugar for a template with an
eponymous class as its only member, the compiler expands it to:

    class D {
        class C {
            bool val;
        }
    }

So of course there's no such thing as d.val.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 12 2012