Improved diagnostics for mismatched template constraints

Per Nordlöw per.nordlow at gmail.com
Wed May 12 12:54:24 UTC 2021


Given

```d
import std.range.primitives : isInputRange;

enum isDumb(Args...) = (Args.length == 2 && Args.length == 3);

void f(Args...)(Args args)
if (isDumb!(Args))
{
}

void g(Arg)(Arg arg)
if (isInputRange!(Arg))
{
}

@safe pure unittest
{
     f(2, 3);
     g(2);
}
```

`dmd` diagnoses the first level as

```
/home/per/f.d(18,6): Error: template `f.f` cannot deduce function 
from argument types `!()(int, int)`, candidates are:
/home/per/f.d(6,6):        `f(Args...)(Args args)`
   with `Args = (int, int)`
   must satisfy the following constraint:
`       isDumb!Args`
/home/per/f.d(19,6): Error: template `f.g` cannot deduce function 
from argument types `!()(int)`, candidates are:
/home/per/f.d(11,6):        `g(Arg)(Arg arg)`
   with `Arg = int`
   must satisfy the following constraint:
`       isInputRange!Arg
```

I'm certain I've seen dmd be able to diagnose which 
sub-expression of `isDumb` and `isInputRange` that evaluated to 
false. Did I just dream this or is there a way? If there is a way 
does this improvement still reside in a dmd PR?


More information about the Digitalmars-d-learn mailing list