D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 9175 - std.algorithm.remove!(predicate) problems
Summary: std.algorithm.remove!(predicate) problems
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-12-17 21:56 UTC by bearophile_hugs
Modified: 2020-03-21 03:56 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-12-17 21:56:35 UTC
This works correctly:

import std.algorithm;
void main() {
    auto array = [40, 20, 10, 30];
    array = remove!"a <= 20"(array); // OK
    assert(array == [40, 30]);
}



This doesn't compile:

import std.algorithm;
void main() {
    auto array = [40, 20, 10, 30];
    auto p = (int x) => x <= 20;
    array = remove!p(array); // Error.
    assert(array == [40, 30]);
}



DMD 2.061alpha gives:

test.d(5): Error: variable p cannot be read at compile time


While a module-level function:

import std.algorithm;
bool p(int x) { return x <= 20; }
void main() {
    auto array = [40, 20, 10, 30];
    array = remove!p(array);
    assert(array == [40, 30]);
}


DMD gives:

...\dmd2\src\phobos\std\algorithm.d(6843): Error: not a property p
...\dmd2\src\phobos\std\algorithm.d(6949): Error: not a property p
Comment 1 Infiltrator 2015-12-02 16:08:51 UTC
The last example works in 2.069.

The second example looks to be a compiler issue rather than a phobos issue, so I'm changing the component to dmd.
Comment 2 Andrea Fontana 2019-09-17 15:05:10 UTC
In my opinion the second example correctly fails.

Indeed p can't be read at compile time. If you replace auto with enum or immutable the example works fine.

The third example works correctly so I guess we can close this issue.
Comment 3 basile-z 2019-11-19 10:01:00 UTC
or alias