article comparing Rust and Zig, many points relevant to D

Walter Bright newshound2 at digitalmars.com
Thu Mar 11 03:19:15 UTC 2021


On 3/10/2021 10:08 AM, H. S. Teoh wrote:
> On Wed, Mar 10, 2021 at 05:59:56PM +0000, VF via Digitalmars-d wrote:
> [...]
>> Speaking of bugginess, here's the latest bug that I noticed (dmd 2.094):
>>
>> mixin template X() { int x; }
>>
>> struct A { mixin X; int x; } // <- that compiles!
> 
> This is not a bug. It's a feature. (Although its value is debatable.)
> Mixins exist in separate namespaces, which can be useful if you have
> multiple mixins that declare the same identifier. Note that there's an
> optional identifier after `mixin X` that can be used to disambiguate
> between the two instances of `x`, e.g.:
> 
> 	struct A {
> 		mixin X x2;
> 		int x;
> 	}
> 
> 	A.x2.x = 1;
> 	a.x = 2;

You're right, it's quite deliberate. Template mixins would be fairly crippled if 
it didn't.


More information about the Digitalmars-d mailing list