Skip to content

Commit

Permalink
Merge pull request #630 from jmdavis/8233
Browse files Browse the repository at this point in the history
Fix for issue# 8233.
  • Loading branch information
jmdavis committed Jun 14, 2012
2 parents 646bb9e + 5c3d219 commit c05e6e4
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions std/array.d
Expand Up @@ -39,7 +39,7 @@ if (isIterable!Range && !isNarrowString!Range)
{
if(r.length == 0) return null;

auto result = uninitializedArray!(E[])(r.length);
auto result = uninitializedArray!(Unqual!(E)[])(r.length);

size_t i = 0;
foreach (e; r)
Expand All @@ -56,7 +56,7 @@ if (isIterable!Range && !isNarrowString!Range)
}
i++;
}
return result;
return cast(E[])result;
}
else
{
Expand Down Expand Up @@ -138,6 +138,34 @@ unittest
assert(array("ABC".dup) == "ABC"d.dup);
}

//Bug# 8233
unittest
{
assert(array("hello world"d) == "hello world"d);
immutable a = [1, 2, 3, 4, 5];
assert(array(a) == a);
const b = a;
assert(array(b) == a);

//To verify that the opAssign branch doesn't get screwed up by using Unqual.
struct S
{
ref S opAssign(S)(const ref S rhs)
{
i = rhs.i;
return this;
}

int i;
}

foreach(T; TypeTuple!(S, const S, immutable S))
{
auto arr = [T(1), T(2), T(3), T(4)];
assert(array(arr) == arr);
}
}

private template blockAttribute(T)
{
static if (hasIndirections!(T) || is(T == void))
Expand Down

0 comments on commit c05e6e4

Please sign in to comment.