Better error messages - from reddit
Nicholas Wilson
iamthewilsonator at hotmail.com
Tue Mar 5 01:49:26 UTC 2019
On Tuesday, 5 March 2019 at 01:18:05 UTC, H. S. Teoh wrote:
> Well, if you're looking for a perfect solution, then yes this
> will be very complicated and hairy to implement.
Unfortunately both options are going to be nasty to implement
because of the way that the compiler works, namely that you need
to reevaluate the expressions and print their source. This sounds
trivial, but because the constraint is boolean the result is
overridden, so you need to look at the template declaration's
constraint and reevaluate that, but then all the templates that
are used in the expression are already instantiated so all you
get from `isInputRange!R && isFoo!Bar` is `true && false` so you
have to flush the template cache (which fortunately is fine
because at this point you know the compiler is going to give an
error). There is possibly a way to get back at the source from
the location but I haven't got that far.
> 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).
You don't actually get (A && B && C && ...) you get (A && (B &&
(C && ...))) (at least I think thats what you get I haven't been
able to confirm the exact AST)
each of which could contain arbitrary conjugation, so you need to
recurse and that hurts my head.
> 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.
Fear not, I'm going to use Dconf to get through all the
bureaucracy (and get help with the implementation).
More information about the Digitalmars-d
mailing list