digitalmars.D.learn - Why can't I assign a mixin to an alias?
- Dechcaudron (15/15) Jun 10 2016 I have the following code:
- Mihail-K (6/21) Jun 10 2016 I'm no expert, but this looks like a grammar issue more than
- David Nadlinger (6/9) Jun 10 2016 This might be a gratuitous grammar restriction. There are a few
- Dechcaudron (3/7) Jun 12 2016 It seems to be that it would be a good idea to file this in as a
- Alex Parrill (3/18) Jun 10 2016 Mixins are statements. They cannot be a part of an expression.
- Adam D. Ruppe (7/8) Jun 10 2016 No, they're not. Well, yes they are [1], but there are also mixin
- Alex Parrill (4/12) Jun 10 2016 Huh, every time I've used mixins, I've always run into the issue
I have the following code: private string getVariableSignalWrappersName(VarType)() { return VarType.stringof ~ "SignalWrappers"; } void addVariableListener(VarType)(int variableIndex, void delegate(int, VarType)) { alias typeSignalWrappers = mixin(getVariableSignalWrappersName!VarType); } On compilation, the following error is issued: Error: basic type expected, not mixin Why should it be like that? I believe the compiler should not impose restrictions on what mixins can or cannot do :/
Jun 10 2016
On Friday, 10 June 2016 at 22:38:29 UTC, Dechcaudron wrote:I have the following code: private string getVariableSignalWrappersName(VarType)() { return VarType.stringof ~ "SignalWrappers"; } void addVariableListener(VarType)(int variableIndex, void delegate(int, VarType)) { alias typeSignalWrappers = mixin(getVariableSignalWrappersName!VarType); } On compilation, the following error is issued: Error: basic type expected, not mixin Why should it be like that? I believe the compiler should not impose restrictions on what mixins can or cannot do :/I'm no expert, but this looks like a grammar issue more than anything else. You can work around it by moving the alias declaration into the mixin. mixin("alias typeSignalWrappers = " ~ getVariableSignalWrappersName!VarType ~ ";");
Jun 10 2016
On Friday, 10 June 2016 at 22:38:29 UTC, Dechcaudron wrote:Error: basic type expected, not mixin Why should it be like that? I believe the compiler should not impose restrictions on what mixins can or cannot do :/This might be a gratuitous grammar restriction. There are a few of those surrounding alias "targets". A template that simply returns its parameter might work, though, such as std.meta.Alias (alias foo = Alias!(mixin(…));). — David
Jun 10 2016
On Saturday, 11 June 2016 at 01:53:10 UTC, David Nadlinger wrote:This might be a gratuitous grammar restriction. There are a few of those surrounding alias "targets". A template that simply returns its parameter might work, though, such as std.meta.Alias (alias foo = Alias!(mixin(…));).It seems to be that it would be a good idea to file this in as a suggested change/fix. Do I have support?
Jun 12 2016
On Friday, 10 June 2016 at 22:38:29 UTC, Dechcaudron wrote:I have the following code: private string getVariableSignalWrappersName(VarType)() { return VarType.stringof ~ "SignalWrappers"; } void addVariableListener(VarType)(int variableIndex, void delegate(int, VarType)) { alias typeSignalWrappers = mixin(getVariableSignalWrappersName!VarType); } On compilation, the following error is issued: Error: basic type expected, not mixin Why should it be like that? I believe the compiler should not impose restrictions on what mixins can or cannot do :/Mixins are statements. They cannot be a part of an expression. The other two posts have demonstrated how to get around this.
Jun 10 2016
On Saturday, 11 June 2016 at 02:33:46 UTC, Alex Parrill wrote:Mixins are statements.No, they're not. Well, yes they are [1], but there are also mixin expressions [2]. Not to be confused with the TemplateMixin[3], which is indeed always a statement. 1: http://dlang.org/spec/grammar.html#MixinExpression 2: http://dlang.org/spec/grammar.html#MixinStatement 3: http://dlang.org/spec/grammar.html#TemplateMixin
Jun 10 2016
On Saturday, 11 June 2016 at 02:46:00 UTC, Adam D. Ruppe wrote:On Saturday, 11 June 2016 at 02:33:46 UTC, Alex Parrill wrote:Huh, every time I've used mixins, I've always run into the issue in the OP, so I assumed they were statements. It definitely seems like a bug then.Mixins are statements.No, they're not. Well, yes they are [1], but there are also mixin expressions [2]. Not to be confused with the TemplateMixin[3], which is indeed always a statement. 1: http://dlang.org/spec/grammar.html#MixinExpression 2: http://dlang.org/spec/grammar.html#MixinStatement 3: http://dlang.org/spec/grammar.html#TemplateMixin
Jun 10 2016