D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3311 - std.range.chain shouldn't have opIndexAssign if arguments aren't mutable.
Summary: std.range.chain shouldn't have opIndexAssign if arguments aren't mutable.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2009-09-11 07:50 UTC by David Simcha
Modified: 2015-06-09 01:26 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 David Simcha 2009-09-11 07:50:39 UTC
import std.range;

void main() {
    immutable(uint)[] foo = [1,2,3,4,5];
    immutable(uint)[] bar = [6,7,8,9,10];
    auto baz = chain(foo, bar);
}

C:\dmd2\windows\bin\..\..\src\phobos\std\range.d(930): Error: this._input._field_field_0[index] isn't mutable
C:\dmd2\windows\bin\..\..\src\phobos\std\range.d(930): Error: this._input._field_field_1[index] isn't mutable


This is too simple to fix to do a formal patch, but here's an "inline patch":

/**Tests whether a type is mutable, i.e. not const or immutable.  This is only
 * tested at the shallowest level, not transitively.  For example, an
 * immutable(uint)[] would be considered mutable.*/
template isMutable(T) {
    enum isMutable = !is(T == const(T));
}

unittest {
    static assert(isMutable!(ElementType!(uint[])));
    static assert(isMutable!(ElementType!(float[])));
    static assert(!isMutable!(ElementType!(string)));
    static assert(isMutable!(ElementType!(string[])));
    static assert(!isMutable!(ElementType!(const(char)[])));
    static assert(isMutable!string);
}


And in std.range.chainImpl:

static if (allSameType) void opIndexAssign(ElementType v, uint index)

should be changed to

static if (allSameType && isMutable!(ElementType))
void opIndexAssign(ElementType v, uint index)
Comment 1 David Simcha 2009-12-01 06:21:48 UTC
Fixed SVN.
Comment 2 Walter Bright 2009-12-06 00:50:58 UTC
Fixed dmd 2.037