www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11218] New: alias this and mixin templates should be interchangeable

http://d.puremagic.com/issues/show_bug.cgi?id=11218

           Summary: alias this and mixin templates should be
                    interchangeable
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: eberhardhoepfner gmx.de


--- Comment #0 from Eberhard <eberhardhoepfner gmx.de> 2013-10-10 10:36:35 PDT
---
mixin templates and alias-this are really the same thing, the first being a
static mixin, the second a dynamic mixin. So I expect them to be
interchangeable:


import std.stdio;
mixin template T() {
    void foo() {  writeln("mixin"); }
}
class C {
    void foo() { writeln("mixin"); }
}
class Outer {
    void foo() {  writeln("outer"); }
    class Inner {
        static const bool TEMPLATE = true;
        static if (TEMPLATE) {
            mixin T;
        } else {
            C c = new C;
            alias c this;
        }
        void test() {
            foo();
        }
    }
    void test() {
        Inner i = new Inner;
        i.test();
    }
}
void main(string[] args) {
    Outer o = new Outer;
    o.test();
}

Output:
  TEMPLATE == true:   "mixin"
  TEMPLATE == false:  "outer"  <-- should be "mixin"!


I expect alias-this to behave like a mixin template:

class C {
    void foo() {}
}
class Outer {
    void foo() {}
    static class Inner {
        C c = new C;
        alias c this;
        void test() {
            foo(); // Error
        }
    }
}

test.d(10): Error: this for foo needs to be type Outer not type
test.Outer.Inner

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 10 2013