Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/core/internal/arrayop.d
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ bool isUnaryOp(string op)

bool isBinaryOp(string op)
{
if (op == "^^")
return true;
if (op.length != 1)
return false;
switch (op[0])
Expand All @@ -191,7 +193,7 @@ bool isBinaryOp(string op)

bool isBinaryAssignOp(string op)
{
return op.length == 2 && op[1] == '=' && isBinaryOp(op[0 .. 1]);
return op.length >= 2 && op[$ - 1] == '=' && isBinaryOp(op[0 .. $ - 1]);
}

// Generate mixin expression to perform scalar arrayOp loop expression, assumes
Expand Down Expand Up @@ -374,6 +376,8 @@ unittest
{
test!(T, "+")(1, 2, 3);
test!(T, "-")(3, 2, 1);
static if (__traits(compiles, { import std.math; }))
test!(T, "^^")(2, 3, 8);

test2!(T, "u-", "+")(3, 2, 1);
}
Expand Down Expand Up @@ -402,13 +406,19 @@ unittest
}
}

// test rewrite of v op= exp to v = v op exp
// test handling of v op= exp
unittest
{
byte[32] c;
arrayOp!(byte[], byte, "+=")(c[], cast(byte) 6);
uint[32] c;
arrayOp!(uint[], uint, "+=")(c[], 2);
foreach (v; c)
assert(v == 6);
assert(v == 2);
static if (__traits(compiles, { import std.math; }))
{
arrayOp!(uint[], uint, "^^=")(c[], 3);
foreach (v; c)
assert(v == 8);
}
}

// proper error message for UDT lacking certain ops
Expand Down