Bug 11218 – alias this and mixin templates should be interchangeable

Status
REOPENED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-10T10:36:35Z
Last change time
2024-12-13T18:12:34Z
Assigned to
No Owner
Creator
Eberhard
Moved to GitHub: dmd#18693 →

Comments

Comment #0 by eberhardhoepfner — 2013-10-10T10:36:35Z
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
Comment #1 by robert.schadek — 2024-12-13T18:12:34Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18693 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB