Better error messages - from reddit
Nicholas Wilson
iamthewilsonator at hotmail.com
Fri Mar 8 09:08:44 UTC 2019
On Friday, 8 March 2019 at 08:19:41 UTC, Johannes Pfau wrote:
> OK, I see. For multiple parameters a CNF form is indeed the
> natural description. However, the DIP probably wouldn't be
> needed with traits(constraintsCheck) as multiple error
> reporting would also work with a CNF of implements!T or other
> constraints. One thing a simple traits(constraintsCheck) can
> probably not handle easily is pointing out which of the
> implements!T calls caused the errors,
That is why this is orthogonal to the DIP, nothing stops us doing
both.
> though if we detect CNF in the compiler that could work. Really
> difficult are more complicated constructs such as
> (isSomething!(A, B) || isSomething!(A, C)).
No, _really_ difficult constraints are recursive on variable
arguments
ptrdiff_t countUntil(alias pred = "a == b", R, Rs...)(R haystack,
Rs needles)
if (isForwardRange!R
&& Rs.length > 0
&& isForwardRange!(Rs[0]) == isInputRange!(Rs[0])
&& is(typeof(startsWith!pred(haystack, needles[0])))
&& (Rs.length == 1
|| is(typeof(countUntil!pred(haystack, needles[1 .. $])))))
https://github.com/dlang/phobos/blob/master/std/algorithm/searching.d#L768
> Here traits(constraintsCheck) would produce all messages for
> both checks if both fail.
List the output for a predicate that is invalid for the second
needle, or a second needle that is an input range but not a
forward range or a second needle that is not an input range but
fails for some other reason.
In the first case you're in an is expression and typeof and the
constraint comes from the failed constraint of the recursion of
the current template that depends on another template (startsWith)
The second still doesn't enable expressing the fact the
countUntil requires needles to either be elements or forward
ranges, which is not at all obvious from the expression used to
encode the sub-constraint.
The third you _have to_ use the CNF property or else you'll emit
errors for unrelated things.
More information about the Digitalmars-d
mailing list