Postmortem: Template unittests are bad & you shouldn't catch Error

Timon Gehr timon.gehr at gmx.ch
Thu Oct 22 16:28:18 UTC 2020


On 22.10.20 18:26, Timon Gehr wrote:
> On 22.10.20 18:05, Mathias LANG wrote:
>>>
>>
>> You disagree with the spec then. The spec says that the stack might 
>> not be unwound if an `Error` is thrown. Walter even raised a PR to 
>> actually do the optimization the spec promises. In his words:
>>
>>> This PR is still the right thing to do. Attempting to unwind when an 
>>> Error is thrown is a bad idea, and leads to undefined behavior. 
>>> Essentially, code which relies on such unwinding needs to be fixed.
>>
>> Source: https://github.com/dlang/dmd/pull/6896#issuecomment-362855793
> 
> It's not that simple. The compiler itself catches AssertError when 
> checking preconditions.

Also, code that "relies on such unwinding" can be annotated @safe and 
the compiler won't complain.

The issue is not that people disagree with the specification, it's that 
the specification disagrees with itself.


More information about the Digitalmars-d mailing list