Bug 23769 – Lambda isn't a unary predicate for lambda that doesn't compile
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-03-10T13:51:31Z
Last change time
2023-04-10T16:10:26Z
Keywords
pull
Assigned to
No Owner
Creator
Grim Maple
Comments
Comment #0 by grimmaple95 — 2023-03-10T13:51:31Z
class A{
bool t;
}
void main()
{
A[] a = new A[100];
writeln(a.all!(x => x.b));
}
This code errors at compile with:
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/searching.d(124): Error: static assert: "`__lambda2` isn't a unary predicate function for range.front"
onlineapp.d(10): instantiated from here: `all!(A[])`
It should just output that the lambda doesn't compile.
I'm not sure if it's related to https://issues.dlang.org/show_bug.cgi?id=11907
Comment #1 by nick — 2023-03-11T13:32:14Z
This is essentially the same as issue 13683, though that was fixed by adding the static assert, though the message doesn't mention that the lambda may not be valid. (It was then widened afterwards and reopened because `all` is unusual in that it uses a static assert instead of a constraint and the rest of Phobos would need adjusting to do the same).
Comment #2 by dlang-bot — 2023-03-13T12:12:17Z
@ntrel created dlang/phobos pull request #8715 "[std.algorithm.searching] Don't check template lambda compiles for `all` and `any`" fixing this issue:
- [std.algorithm.searching] Don't instantiate template pred in `all` and `any` constraints
Fixes Issue 23769 - Lambda isn't a unary predicate for lambda that
doesn't compile.
https://github.com/dlang/phobos/pull/8715
Comment #3 by razvan.nitu1305 — 2023-03-13T15:54:18Z
Indeed, this is not a compiler issue. It has to do with how the phobos template is written. I don't see how the compiler can be fixed to prevent the error message of a static assert in the standard library.
Comment #4 by dlang-bot — 2023-04-10T16:10:26Z
dlang/phobos pull request #8715 "[std.algorithm.searching] Don't check template lambda compiles for `all` and `any`" was merged into master:
- bb49ffb9e75240e0389d2f30182c4a7634a00d7f by Nick Treleaven:
[std.algorithm.searching] Don't instantiate template pred in `all` and `any` constraints
Fixes Issue 23769 - Lambda isn't a unary predicate for lambda that
doesn't compile.
https://github.com/dlang/phobos/pull/8715