February 01, 2023 [Issue 13683] More precise error message for wrong lambda | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13683 Nick Treleaven <nick@geany.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://issues.dlang.org/sh | |ow_bug.cgi?id=23663 -- |
March 11, 2023 [Issue 13683] More precise error message for wrong lambda | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13683 --- Comment #5 from Nick Treleaven <nick@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. -- |
March 11, 2023 [Issue 13683] More precise error message for wrong lambda | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=13683 --- Comment #6 from Nick Treleaven <nick@geany.org> --- > Without a compiler solution BTW that would show the failing lambda with Phobos as is. The static assert PR discussion said a compiler solution is needed rather than having to update every template that accepts a lambda in Phobos. -- |
Copyright © 1999-2021 by the D Language Foundation