Bug or intentional error?
Meta via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 7 19:53:24 PDT 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:
>> 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.
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.
More information about the Digitalmars-d
mailing list