D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5575 - Problem with a map() of a const uniq()
Summary: Problem with a map() of a const uniq()
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-14 11:03 UTC by bearophile_hugs
Modified: 2024-12-13 17:54 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-02-14 11:03:24 UTC
D2 code. map() doesn't modify the input range, so I think this is correct (but I am not sure if it's correct. A mutable range of immutable items isn't the same thing as an immutable range):


import std.algorithm;
void main() {
    auto u1 = uniq([1]);
    auto m1 = map!q{ a }(u1); // OK
    const u2 = u1;
    auto m2 = map!q{ a }(u2); // Error
}


DMD 2.051 gives:

...\dmd\src\phobos\std\algorithm.d(109): Error: constructor std.algorithm.Map!(result,const(Uniq!(pred,int[]))).Map.this (Uniq!(pred,int[]) input) is not callable using argument types (const(Uniq!(pred,int[])))
...\dmd\src\phobos\std\algorithm.d(109): Error: cannot implicitly convert expression (r) of type const(Uniq!(pred,int[])) to Uniq!(pred,int[])
test4.d(6): Error: template instance std.algorithm.map!(" a ").map!(const(Uniq!(pred,int[]))) error instantiating
Comment 1 bearophile_hugs 2012-02-03 15:41:44 UTC
This seems related, DMD 2.058head:


import std.algorithm, std.array;
void main() {
    auto s1 = "hello";
    auto m1 = map!(c => c)(s1);
    auto a1 = array(m1); // OK
    auto s2 = "hello"d;
    auto m2 = map!(c => c)(s2);
    auto a2 = array(m2); // line 8, Error
}


...\dmd2\src\phobos\std\array.d(55): Error: result[i] isn't mutable
test.d(8): Error: template instance std.array.array!(Result) error instantiating
Comment 2 dlangBugzillaToGithub 2024-12-13 17:54:48 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18329

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB