digitalmars.D - Why do template mixins have their own scope?
- Trass3r (4/4) Jul 16 2011 I guess this is the cause for
- Timon Gehr (10/14) Jul 16 2011 mixin template foo(){
- Trass3r (1/16) Jul 16 2011
- Trass3r (3/3) Jul 16 2011 I know but what is so bad about issuing an error message and you rename ...
- Timon Gehr (11/14) Jul 17 2011 First of all, you would break some existing code for no benefit, includi...
- Trass3r (2/3) Jul 17 2011 It isn't limited to constructors. Overload resolution for any function
- Jacob Carlborg (8/12) Jul 17 2011 I've been knowing that template mixins behave like this for a long time....
I guess this is the cause for http://d.puremagic.com/issues/show_bug.cgi?id=3332 It makes it practically impossible to mixin constructors because overload resolution doesn't work.
Jul 16 2011
Trass3r wrote:I guess this is the cause for http://d.puremagic.com/issues/show_bug.cgi?id=3332 It makes it practically impossible to mixin constructors because overload resolution doesn't work.mixin template foo(){ immutable x = 1; int bar(){return x;} } immutable x = 2; mixin foo!(); void main(){assert(bar == 1);} Cheers, -Timon
Jul 16 2011
Am 16.07.2011, 20:41 Uhr, schrieb Timon Gehr <timon.gehr gmx.ch>:Trass3r wrote:I guess this is the cause for http://d.puremagic.com/issues/show_bug.cgi?id=3332 It makes it practically impossible to mixin constructors because overload resolution doesn't work.mixin template foo(){ immutable x = 1; int bar(){return x;} } immutable x = 2; mixin foo!(); void main(){assert(bar == 1);} Cheers, -Timon
Jul 16 2011
I know but what is so bad about issuing an error message and you rename one of the two. As I said it doesn't work out as soon as functions are involved.
Jul 16 2011
Trass3r wrote:I know but what is so bad about issuing an error message and you rename one of the two. As I said it doesn't work out as soon as functions are involved.First of all, you would break some existing code for no benefit, including code that mixes in two templates with clashing members. Furthermore, it would be more difficult to implement, because templates already come with their own scope. Mixin templates are there to allow mixing in declarations without coping with the problems of string mixins. An own scope is pretty much required for that. Therefore, I think mixin templates having their own scope is sensible. The bug fix is to just search for constructors in mixin scopes too. Cheers, -Timon
Jul 17 2011
The bug fix is to just search for constructors in mixin scopes too.It isn't limited to constructors. Overload resolution for any function needs to be fixed.
Jul 17 2011
On 2011-07-16 20:32, Trass3r wrote:I guess this is the cause for http://d.puremagic.com/issues/show_bug.cgi?id=3332 It makes it practically impossible to mixin constructors because overload resolution doesn't work.I've been knowing that template mixins behave like this for a long time. Don't know why I created that ticket, must have forgotten how mixins work. What is confusing is that the documentation says that a template mixin is just like copying the code and pasting it in the mixin place. Which it's not, shown by this ticket. -- /Jacob Carlborg
Jul 17 2011