Skip to content

Commit

Permalink
Merge pull request #8988 from ibuclaw/merge_stable
Browse files Browse the repository at this point in the history
merge stable
  • Loading branch information
ibuclaw committed Apr 26, 2024
2 parents 4b2ea30 + 688816e commit 54eb95c
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .dscanner.ini
Expand Up @@ -52,7 +52,7 @@ comma_expression_check="enabled"
; Checks for local imports that are too broad
local_import_check="skip-unittest"
; Checks for variables that could be declared immutable
could_be_immutable_check="enabled"
could_be_immutable_check="skip-unittest"
; Checks for redundant expressions in if statements
redundant_if_check="enabled"
; Checks for redundant parenthesis
Expand Down
91 changes: 91 additions & 0 deletions std/internal/test/range.d
Expand Up @@ -23,3 +23,94 @@ module std.internal.test.range;
auto r = R().chunks(3);
assert(r.equal!equal([[ 0, 1, 2 ], [ 3, 4 ]]));
}

// https://issues.dlang.org/show_bug.cgi?id=24415
@safe unittest
{
import std.range : only;

static struct S(T)
{
T i;

this(ref return scope inout(S) rhs) scope @safe inout pure nothrow
{
i = rhs.i;
}
}
{
auto a = only(S!int(42));
auto b = a;
assert(!b.empty);
assert(b.front == S!int(42));

a.popFront();
auto c = a;
assert(c.empty);
}
{
auto a = only(S!(const int)(42));
auto b = a;
assert(!b.empty);
assert(b.front == S!(const int)(42));

a.popFront();
auto c = a;
assert(c.empty);
}
{
auto a = only(S!(immutable int)(42));
auto b = a;
assert(!b.empty);
assert(b.front == S!(immutable int)(42));

a.popFront();
auto c = a;
assert(c.empty);
}
{
auto a = only(S!int(42), S!int(192));
auto b = a;
assert(!b.empty);
assert(b.front == S!int(42));

a.popFront();
auto c = a;
assert(!c.empty);
assert(c.front == S!int(192));

a.popFront();
auto d = a;
assert(d.empty);
}
{
auto a = only(S!(const int)(42), S!(const int)(192));
auto b = a;
assert(!b.empty);
assert(b.front == S!(const int)(42));

a.popFront();
auto c = a;
assert(!c.empty);
assert(c.front == S!(const int)(192));

a.popFront();
auto d = a;
assert(d.empty);
}
{
auto a = only(S!(immutable int)(42), S!(immutable int)(192));
auto b = a;
assert(!b.empty);
assert(b.front == S!(immutable int)(42));

a.popFront();
auto c = a;
assert(!c.empty);
assert(c.front == S!(immutable int)(192));

a.popFront();
auto d = a;
assert(d.empty);
}
}
8 changes: 8 additions & 0 deletions std/range/package.d
Expand Up @@ -10398,6 +10398,14 @@ private struct OnlyResult(T)
}
alias opDollar = length;

// FIXME Workaround for https://issues.dlang.org/show_bug.cgi?id=24415
import std.traits : hasElaborateCopyConstructor;
static if (hasElaborateCopyConstructor!T)
{
private static struct WorkaroundBugzilla24415 {}
public this()(WorkaroundBugzilla24415) {}
}

private this()(return scope auto ref T value)
{
ref @trusted unqual(ref T x){return cast() x;}
Expand Down

0 comments on commit 54eb95c

Please sign in to comment.