The evils of __traits(compiles)

Paul Backus snarwin at gmail.com
Thu Jan 21 20:45:50 UTC 2021


On Thursday, 21 January 2021 at 20:27:36 UTC, H. S. Teoh wrote:
> Unfortunately, my PR touches one of the functions used by 
> setHandler. A typo caused a compile error inside setHandler 
> itself, but since __traits(compiles) does not distinguish 
> between errors caused by the candidate method and errors inside 
> setHandler itself, the erroneous code simply caused *all* 
> methods to be skipped -- silently.  The problem would not be 
> noticed until runtime when some methods mysteriously go 
> missing. :-(

This seems like a bug that would have been easily caught by a 
unit test for setHandler.

Remember: the compiler does not check your templates until you 
actually try to instantiate them. If you want to be sure that 
they instantiate correctly, you have to test them.


More information about the Digitalmars-d mailing list