[Issue 13683] More precise error message for wrong lambda

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 11 15:15:51 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=13683

--- Comment #5 from Nick Treleaven <nick at geany.org> ---
static assert is an improvement over the constraint, but it still hides the
actual error message which should be:

Error: use `!is` instead of `!=` when comparing with `null`

Removing the constraint allows the correct error to be seen. But then the
constraint may be needed to disambiguate overloads. Without a compiler
solution,  we could have a new trait - __traits(canPass, pred, range.front)
which ignores the body of pred:

https://forum.dlang.org/post/lekofsbnstkoqpspramg@forum.dlang.org

In the absence of that, the best I've come up with is:

if (__traits(isTemplate, pred) || is(typeof(pred(range.front))))

Which doesn't check that pred can take that argument when pred is a lambda, but
it doesn't hide the actual error unlike the constraint status quo or the static
assert way.

A compiler solution might not work in the presence of overloads, because
currently failing constraints are only shown when there are no overloads.

--


More information about the Digitalmars-d-bugs mailing list