My late christmas present for you: context-aware assertion error messages
Seb
seb at wilzba.ch
Mon Jan 14 15:41:31 UTC 2019
On Monday, 14 January 2019 at 14:15:45 UTC, Atila Neves wrote:
> On Saturday, 12 January 2019 at 15:34:02 UTC, Seb wrote:
>> tl;dr: I was annoyed for years that D's assert are so non
>> informative AssertError, so here's my late Christmas present
>> for the D community. With 2.085 DMD will gain an experimental
>> flag for more informative assertion errors. Feedback on this
>> experimental feature is welcome, s.t. we eventually can enable
>> it by default.
>>
>> [...]
>
> Awesome.
>
> It's obvious that assertions for equality are the most common,
> I wonder how easy it would be to get other changes merged like
> `assert(foo in bar)`.
Should be easy enough:
https://github.com/dlang/dmd/pull/9264
https://github.com/dlang/druntime/pull/2463
Also note that other trivial stuff like `a < b` is already
supported.
See e.g.:
https://github.com/dlang/druntime/blob/master/test/exceptions/src/assert_fail.d
> There are also all the assertions that make use of `equal`
> because of ranges.
In theory we could hard-code a check for the symbol in DMD and
see whether its std.algorithm.comparison.equal, but ranges are
tricky as both might have been consumed by `equal` and you would
then end up printing e.g. sth. like:
[] != []
> I'd really like is access to the AST in the assert but alas I
> don't think that will ever be possible.
Yeah :/
More information about the Digitalmars-d
mailing list