Better error messages - from reddit

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Mar 5 01:18:05 UTC 2019


On Tue, Mar 05, 2019 at 12:44:25AM +0000, Nicholas Wilson via Digitalmars-d wrote:
> On Tuesday, 5 March 2019 at 00:03:39 UTC, H. S. Teoh wrote:
[...]
> > Given that programmers tend to be lazy (why spend the time writing
> > elaborate sig constraints when I could be working on the function
> > body where the real work is done), having the compiler able to emit
> > useful information *without help from the programmer* is a big plus.
> > 
> > An even bigger plus is that it can be done today with just a little
> > change in the compiler.
> 
> ... the problem (from the perspective of issuing a nice error) is that
> you can arbitrarily compose logic which makes sorting the what from
> the chaff extremely difficult and that signal to noise is very
> important (ever used -verrors=spec ?). Believe me I tried, saw a
> suggestion by aliak in a Phobos PR thread and thought that would make
> things so much easier, and thus arose that DIP.

Well, if you're looking for a perfect solution, then yes this will be
very complicated and hairy to implement.

But to take care of the most common case, all we have to do is to assume
that sig constraints are of the form (A && B && C && ...).  The compiler
only needs to report which of these top level conjuncts failed.  If a
sig constraint isn't of this form, then fallback to reporting the entire
constraint as failed, i.e., treat it as the case (A) (single-argument
conjunction).

It's not a perfect solution, but having this is already a lot better
than the current pessimal state of things.  Your DIP represents an
improvement over this most basic step, but IMO we should at least have
this basic step first.  Don't let the perfect become the enemy of the
good yet again.


T

-- 
Amateurs built the Ark; professionals built the Titanic.


More information about the Digitalmars-d mailing list