digitalmars.D - Bug or intentional error?
- Daniel N (13/13) Jul 07 2015 Error: this is not in a class or struct scope
- Tofu Ninja (5/18) Jul 07 2015 Pretty sure that is expected. Default params are evaluated in the
- Meta (6/27) Jul 07 2015 From http://dlang.org/template-mixin.html:
Error: this is not in a class or struct scope mixin template NodeT1(T = typeof(this)) { } mixin template NodeT2() { alias T = typeof(this); } struct Node { mixin NodeT1; // fail mixin NodeT2; // pass }
Jul 07 2015
On Tuesday, 7 July 2015 at 20:08:10 UTC, Daniel N wrote:Error: this is not in a class or struct scope mixin template NodeT1(T = typeof(this)) { } mixin template NodeT2() { alias T = typeof(this); } struct Node { mixin NodeT1; // fail mixin NodeT2; // pass }Pretty sure that is expected. Default params are evaluated in the declaration scope, so typeof(this) is not defined in NodeT1. The only things that break this rule are the special identifiers like __FILE__ which are evaluated at the instantiation/call site.
Jul 07 2015
On Tuesday, 7 July 2015 at 23:40:55 UTC, Tofu Ninja wrote:On Tuesday, 7 July 2015 at 20:08:10 UTC, Daniel N wrote:From http://dlang.org/template-mixin.html: Unlike a template instantiation, a template mixin's **body** is evaluated within the scope where the mixin appears, not where the template declaration is defined. So it looks like your code is working as intended.Error: this is not in a class or struct scope mixin template NodeT1(T = typeof(this)) { } mixin template NodeT2() { alias T = typeof(this); } struct Node { mixin NodeT1; // fail mixin NodeT2; // pass }Pretty sure that is expected. Default params are evaluated in the declaration scope, so typeof(this) is not defined in NodeT1. The only things that break this rule are the special identifiers like __FILE__ which are evaluated at the instantiation/call site.
Jul 07 2015