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

Ethan gooberman at gmail.com
Tue Jul 23 18:36:19 UTC 2019


...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 );


More information about the Digitalmars-d mailing list