You know how I was saying in my DConf talk...

Timon Gehr timon.gehr at gmx.ch
Wed Jul 24 00:51:35 UTC 2019


On 23.07.19 20:36, Ethan wrote:
> ...that I come up across metaprogramming problems that can't be easily 
> Googled and making bug reports for is hard?
> 
> https://issues.dlang.org/show_bug.cgi?id=20072
> 
> I tried upgrading to 2.087.0 and got blindsided by an error that looks 
> something like:
> 
> no property `somevar` for type `some.Type`, did you mean 
> `some.Type.__anonymous.somevar`?
> 
> Writing some entirely unrelated code earlier using 2.086.1 got a similar 
> error and finally twigged me to the fact that it is actually static 
> foreach problem.
> 
> This highlights one of the other things I don't like when errors like 
> this happens: D's quality of error messages is still not great. They've 
> most definitely improved since DDMD happened, but they still seem 
> predicated on the idea that people aren't going to be doing a lot of 
> metaprogramming and provide almost no context when you're deep down the 
> meta hole.
> 
> At least now that I know what the hey is going on, I can actually work 
> at upgrading to 2.087.0 with a workaround, but that legit was going to 
> block me from ever upgrading.
> 
> live code link: https://run.dlang.io/is/PBKQ80
> 
> example code direct:
> 
> import std.meta : AliasSeq;
> import std.traits : moduleName;
> 
> string generateFor( string objectName )()
> {
>      return "struct " ~ objectName ~ "{ }";
> }
> 
> alias StructNames = AliasSeq!( "StructOne", "StructTwo", "StructThree" );
> 
> static foreach( Name; StructNames )
> {
>      mixin( generateFor!Name );
> }
> 
> pragma( msg, moduleName!StructOne );

This shouldn't happen (the anonymous scope is an implementation detail 
and `__traits(parent, ...)` shouldn't return it, especially not for 
symbols that are not even `static foreach` loop variables). Is there 
already an issue for this? Also, this code compiles neither with 2.086.1 
nor 2.087.0. Do you have an example that demonstrates a regression?


More information about the Digitalmars-d mailing list