idea: static scope(failure)

Steven Schveighoffer schveiguy at gmail.com
Tue Apr 19 21:08:20 UTC 2022


On 1/25/22 8:58 PM, Steven Schveighoffer wrote:
> Just recently running into some problems where deeply nested inside some 
> library code, a static assert triggers. Of course, the static assert 
> doesn't give any context with which it was called from *my* code.
> 
> And the compiler helpfully says something like (names changed to protect 
> the proprietary):
> 
> ```
> somelibrary.d(263,16):        instantiated from here: `foo!(Json[string])`
> somelibrary.d(286,25):        instantiated from here: `bar!(Json[string])`
> somelibrary.d(204,16):        instantiated from here: `baz!(Json)`
> somelibrary.d(263,16):        ... (1 instantiations, -v to show) ...
> ```
> 
> OK, so it stopped telling me useful information. And on top of that, the 
> information isn't always enough to determine the cause, because in one 
> of these instantiations, there's probably a static foreach, where I 
> don't know which element being looped over is actually the cause.
> 

Just ran into this again (same project, ironically).

I just had a new idea that maybe could be even better -- the lines above 
specify the line the instantiation happened, and what the template 
parameters are. But what is really missing is the other static 
information. Specifically, which static foreach loop iteration it's in. 
With that, I could piece together what is happening, and no special code 
is necessary to be added to get more diagnostic information.

Maybe only output when -v is specified? One nice thing about failed 
compilation, you can just do it again and it is repeatable.

-Steve


More information about the Digitalmars-d mailing list