alias c=mixin(expr); disallowed, why?

Artur Skawina art.08.09 at gmail.com
Sun Jun 23 03:19:47 PDT 2013


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


More information about the Digitalmars-d-learn mailing list