Thread overview
Huge improvement in error messages in recent dmd
Dec 12, 2019
mipri
Dec 12, 2019
Meta
Dec 12, 2019
Les De Ridder
December 12, 2019
Consider the following code with an error:

  #! /usr/bin/env rdmd
  import std;
  void main() {
      auto pts = Array!(int[])([0, 0], [5, 5], [0, 1], [0, 2]);
      multiSort!("a[0] < b[0]", "a[1] < b[1]", SwapStrategy.unstable)(pts);
  }

The latest version of dmd that's packaged with Fedora is
2.086.1. Of this code it says:

./x266.d(5): Error: template std.algorithm.sorting.multiSort!("a[0] < b[0]", "a[1] < b[1]", cast(SwapStrategy)0).multiSort cannot deduce function from argument types !()(Array!(int[])), candidates are:
/usr/include/dmd/phobos/std/algorithm/sorting.d(1463):        std.algorithm.sorting.multiSort!("a[0] < b[0]", "a[1] < b[1]", cast(SwapStrategy)0).multiSort(Range)(Range r) if (validPredicates!(ElementType!Range, less) && hasSwappableElements!Range)

The nightly I have is v2.089.1-beta.1, and it says:

x266.d(5): Error: template std.algorithm.sorting.multiSort!("a[0] < b[0]", "a[1] < b[1]", cast(SwapStrategy)0).multiSort cannot deduce function from argument types !()(Array!(int[])), candidates are:
/edit/nightly/dmd2/linux/bin64/../../src/phobos/std/algorithm/sorting.d(1466):        multiSort(Range)(Range r)
  with Range = Array!(int[])
  must satisfy the following constraint:
       hasSwappableElements!Range

Which is a huge, huge improvement! The problem is that
Array!(Point) doesn't satisfy hasSwappableElements.

I saw that this was also in the v2.089.0 compiler, and so
checked the blog for announcements back to v2.087, and none of
them showed how much better the error messages got. This should
be highlighted. I don't normally care that much about staying
exactly up-to-date with compilers, but I'd sure have upgraded
earlier for this.

A slightly strange thing is that rdmd's error messages are
even friendlier (v2.089.0):

  ./x266.d(5): Error: template std.algorithm.sorting.multiSort!("a[0] < b[0]", "a[1] < b[1]", cast(SwapStrategy)0).multiSort cannot deduce function from argument types !()(Array!(int[])), candidates are:
  /edit/latest/dmd2/linux/bin64/../../src/phobos/std/algorithm/sorting.d(1466):        multiSort(Range)(Range r)
    with Range = Array!(int[])
    whose parameters have the following constraints:
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      validPredicates!(ElementType!Range, less)
    > hasSwappableElements!Range
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Tip: not satisfied constraints are marked with >

wow!

December 12, 2019
On Thursday, 12 December 2019 at 00:39:15 UTC, mipri wrote:
> Consider the following code with an error:
>
>   #! /usr/bin/env rdmd
>   import std;
>   void main() {
>       auto pts = Array!(int[])([0, 0], [5, 5], [0, 1], [0, 2]);
>       multiSort!("a[0] < b[0]", "a[1] < b[1]", SwapStrategy.unstable)(pts);
>   }
>
> The latest version of dmd that's packaged with Fedora is
> 2.086.1. Of this code it says:
>
> ./x266.d(5): Error: template std.algorithm.sorting.multiSort!("a[0] < b[0]", "a[1] < b[1]", cast(SwapStrategy)0).multiSort cannot deduce function from argument types !()(Array!(int[])), candidates are:
> /usr/include/dmd/phobos/std/algorithm/sorting.d(1463):        std.algorithm.sorting.multiSort!("a[0] < b[0]", "a[1] < b[1]", cast(SwapStrategy)0).multiSort(Range)(Range r) if (validPredicates!(ElementType!Range, less) && hasSwappableElements!Range)
>
> The nightly I have is v2.089.1-beta.1, and it says:
>
> x266.d(5): Error: template std.algorithm.sorting.multiSort!("a[0] < b[0]", "a[1] < b[1]", cast(SwapStrategy)0).multiSort cannot deduce function from argument types !()(Array!(int[])), candidates are:
> /edit/nightly/dmd2/linux/bin64/../../src/phobos/std/algorithm/sorting.d(1466):        multiSort(Range)(Range r)
>   with Range = Array!(int[])
>   must satisfy the following constraint:
>        hasSwappableElements!Range
>
> Which is a huge, huge improvement! The problem is that
> Array!(Point) doesn't satisfy hasSwappableElements.
>
> I saw that this was also in the v2.089.0 compiler, and so
> checked the blog for announcements back to v2.087, and none of
> them showed how much better the error messages got. This should
> be highlighted. I don't normally care that much about staying
> exactly up-to-date with compilers, but I'd sure have upgraded
> earlier for this.
>
> A slightly strange thing is that rdmd's error messages are
> even friendlier (v2.089.0):
>
>   ./x266.d(5): Error: template std.algorithm.sorting.multiSort!("a[0] < b[0]", "a[1] < b[1]", cast(SwapStrategy)0).multiSort cannot deduce function from argument types !()(Array!(int[])), candidates are:
>   /edit/latest/dmd2/linux/bin64/../../src/phobos/std/algorithm/sorting.d(1466):        multiSort(Range)(Range r)
>     with Range = Array!(int[])
>     whose parameters have the following constraints:
>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>       validPredicates!(ElementType!Range, less)
>     > hasSwappableElements!Range
>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     Tip: not satisfied constraints are marked with >
>
> wow!

Huh, I thought I was keeping up to date with the stuff in every new release, but apparently not, as I had no idea that template constraint function error messages had been improved.
December 12, 2019
On Thursday, 12 December 2019 at 00:39:15 UTC, mipri wrote:
> [...]
>
> Which is a huge, huge improvement! The problem is that
> Array!(Point) doesn't satisfy hasSwappableElements.
>
> I saw that this was also in the v2.089.0 compiler, and so
> checked the blog for announcements back to v2.087, and none of
> them showed how much better the error messages got. This should
> be highlighted. I don't normally care that much about staying
> exactly up-to-date with compilers, but I'd sure have upgraded
> earlier for this.

I agree, this is easily one of the most significant user experience
improvements in years.