Better error messages - from reddit

Adam D. Ruppe destructionator at gmail.com
Mon Mar 4 23:03:28 UTC 2019


On Monday, 4 March 2019 at 15:47:12 UTC, H. S. Teoh wrote:
> This is why I'm starting to think sig constraints are not the 
> genius idea they first appeared to be.

If the implementation actually told you which individual pieces 
failed (and perhaps even why), I don't think we'd be worried 
about this.

I have before desired color to be used there: a passing 
constraint gets highlighted one way, a failing constraint 
another, and short-circuited constraints get nothing special.

Even without formatting the output, this would very quickly give 
you a menu of what is and isn't working. And with formatting, it 
just gets better. (Though I also say I want XML error messages 
and a dedicated error viewer, so more and less detail is 
available upon request. But even plain text can give a LOT more 
actionable info than it does right now.)

Imagine what we'd say if the error message was not:

ooooo.d(4): Error: template std.algorithm.sorting.sort cannot 
deduce function from argument types !()(FilterResult!(unaryFun, 
int[])), candidates are:
/home/me/d/dmd2/linux/bin32/../../src/phobos/std/algorithm/sorting.d(1847):
    std.algorithm.sorting.sort(alias less = "a < b", SwapStrategy 
ss = SwapStrategy.unstable, Range)(Range r) if ((ss == 
SwapStrategy.unstable && (hasSwappableElements!Range || 
hasAssignableElements!Range) || ss != SwapStrategy.unstable &&
asAssignableElements!Range) && isRandomAccessRange!Range && 
hasSlicing!Range && hasLength!Range)

but rather



ooooo.d(4): Error: template std.algorithm.sorting.sort cannot 
deduce function from argument types
    !()(FilterResult!(unaryFun, int[])), candidates are:
/home/me/d/dmd2/linux/bin32/../../src/phobos/std/algorithm/sorting.d(1847):
    std.algorithm.sorting.sort([collapsed])(Range r)
       if (
         // passed
         (ss == SwapStrategy.unstable &&
         // passed
         (hasSwappableElements!Range || 
hasAssignableElements!Range) ||
          // short-circuited
         ss != SwapStrategy.unstable &&
asAssignableElements!Range)
         // ******* FAILED ***********
         && isRandomAccessRange!Range
         // short-circuited, but would fail
         && hasSlicing!Range && hasLength!Range
       )


That tells you everything you need to know.


More information about the Digitalmars-d mailing list