www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Mixin bug / unhelpful behavior?

reply =?UTF-8?B?Ikx1w61z?= Marques" <luismarques gmail.com> writes:
Consider the following code:

     mixin template Bar()
     {
         void Bar() {};
     }

     void mixin_ok()
     {
         mixin Bar;
         Bar();
     }

     void mixin_not_defined_ok()
     {
         mixin UndefinedMixin; // OK, compile-time error
     }

     void mixin_not_defined_bug()()
     {
         mixin UndefinedMixin; // No error, unless 
mixin_not_defined_bug is called. Bug?
     }

     void mixin_alias()
     {
         alias Foo = Bar;
         mixin Foo;
         //Foo(); // error: template instance Bar!() mixin 
templates are not regular templates
         Bar(); // ok, but not very helpful
     }

Questions:

1) Is it a bug that mixin_not_defined_bug does not produce a 
compile-time error, unless it is called? (DMD64 v2.062, OS X)

2) Wouldn't it make be helpful if "Foo()" did the same thing as 
Bar()?
Apr 23 2013
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Luís Marques:

 1) Is it a bug that mixin_not_defined_bug does not produce a 
 compile-time error, unless it is called? (DMD64 v2.062, OS X)

I think that here D is working according to its current specs. On the other hand this topic was recently discussed and despite Andrei the consensus seems that such error situations should be found by the D compiler. There is an enhancement request on this, I like it, and Walter seems to like the idea.
 2) Wouldn't it make be helpful if "Foo()" did the same thing as 
 Bar()?

Mixin templates are a relatively new feature and maybe that alias use case was not considered, or it was not regarded as important. What are your use cases of aliasing a mixing template? Bye, bearophile
Apr 23 2013
prev sibling parent =?UTF-8?B?Ikx1w61z?= Marques" <luismarques gmail.com> writes:
On Tuesday, 23 April 2013 at 23:25:11 UTC, bearophile wrote:
 Mixin templates are a relatively new feature and maybe that 
 alias use case was not considered, or it was not regarded as 
 important. What are your use cases of aliasing a mixing 
 template?

I'm going to post it in a new thread.
Apr 23 2013