How to debug broken inference?

Steven Schveighoffer schveiguy at gmail.com
Fri May 1 20:40:48 UTC 2020


I have a dilemma here. I have a non-trivial template function which is 
inside a template struct, and this template is inferred to be @system. 
I'm testing using a @safe unittest.

I put @safe on the template to see which calls are actually system, and 
now it compiles.

This is not a solution, because some template parameters might cause the 
function to truly be @system, and then it just won't compile at all.

I'm struggling to try and figure out how to properly make this function. 
Not only am I not sure what to test, but I will have to duplicate the 
function for both @safe and @system versions, or use a mixin.

But this is going to be really painful. I very much depend on the 
compiler inferring safety for templates, and it's what we recommend to 
people who want to build their code for all purposes.

Does anyone have any recommendations of how to approach this? Even if I 
wanted to report a bug, I have no idea why this is happening in this one 
spot. Why can't the compiler *try* @safe and if it doesn't work, just 
decay to @system?

-Steve


More information about the Digitalmars-d mailing list