alias c=mixin(expr); disallowed, why?
Timon Gehr
timon.gehr at gmx.ch
Sun Jun 23 04:23:23 PDT 2013
On 06/23/2013 12:19 PM, Artur Skawina wrote:
> On 06/22/13 21:52, Timothee Cour wrote:
>> Is there a reason the language spec disallows this?
>>
>> ----
>> void main(){
>> auto a=mixin("1");//OK
>> alias b=a;//OK
>> mixin("alias c=a;");//OK
>> // alias c=mixin("a");//NG : Error: basic type expected, not mixin
>> }
>
> How would that be different from "auto c=mixin("a");"?
>
> It's probably clear, but that error message is misleading, so i'll say
> it anyway - the reason why your 'alias' line does not work is because
> alias requires a symbol, but 'mixin()' is an expression.
> Special-casing mixin-expressions (so that they propagate the symbol when
> that is possible would be a bad idea); the other possibility is to allow
> aliasing /expressions/. But that's a bad idea too, and would likely not
> do what you expect it to do. A mixin-less version could be made to work,
> but there are already other ways to get the same effect.
> Hence the above question.
>
> artur
>
mixin template T(alias x){ }
void foo(){ import std.stdio; writeln("foo"); }
void main(){
auto a=mixin("1");
mixin T!a; // ok
mixin T!(mixin("a")); // ok
mixin T!1; // ok (!)
mixin T!(mixin("foo")); // ok (no implicit call)
}
More information about the Digitalmars-d-learn
mailing list