Quality of errors in DMD
Ethan Watson via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 3 03:57:58 PDT 2016
On Friday, 2 September 2016 at 21:52:57 UTC, Walter Bright wrote:
> I understand your concern, and that's why we put a priority on
> fixing asserts that are submitted to bugzilla. But without a
> bug report, we are completely dead in the water in fixing it.
> It is supposed to never happen, that is why we cannot fix them
> in advance.
We have a rule in our codebase, and it's been the same in every
codebase I've worked in professionally. If you throw an assert,
you have to give a reason and useful information in the assert.
Thus, an error in code that looks like:
assert(0);
Makes no sense to me when in this case it could have been:
fatal_error("Invalid type (from %d to %s)", tx->ty,
tx->toChars());
The quality of error reporting has immediately increased. And it
would require the creation of a fatal_error macro that does an
assert. But now I'm not scratching my head wondering what went
wrong in the compiler.
Browsing through that function, I can also see another assert
that doesn't let you use vector types unless you're running a
64-bit build or are on OSX. It doesn't tell me that through an
error message. I had to look at the source code to work it out.
fatal_error("Vector types unavailable on the target platform");
and someone's day was made better. And then a couple of lines
above that, another assert(0). fatal_error("Invalid vector type
%s", tx->toChars()); and someone can deal with the unexpected.
If I have to open up the compiler's source to get an idea of what
I'm doing wrong, that's a bad user experience. And why I want a
discussion about this. Not to whinge, not to get a bug fix. But
to highlight that assert(0) is a bad pattern and there should be
a discussion about changing the usage of asserts inside DMD.
More information about the Digitalmars-d
mailing list