Skip to content

Commit

Permalink
Fix Issue 18985 - bad error message for += operation on shared Object
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 committed Jun 18, 2018
1 parent 7bf48f8 commit ff23072
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4113,9 +4113,6 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return;
}

if (exp.e1.checkReadModifyWrite(exp.op, exp.e2))
return setError();

if (exp.e1.op == TOK.arrayLength)
{
// arr.length op= e2;
Expand Down Expand Up @@ -4152,7 +4149,16 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
exp.e1 = exp.e1.optimize(WANTvalue);
exp.e1 = exp.e1.modifiableLvalue(sc, exp.e1);
exp.type = exp.e1.type;
if (exp.checkScalar())

if (auto ad = isAggregate(exp.e1.type))
{
if (const s = search_function(ad, Id.opOpAssign))
{
error(exp.loc, "none of the `opOpAssign` overloads of `%s` are callable for `%s` of type `%s`", ad.toChars(), exp.e1.toChars(), exp.e1.type.toChars());
return setError();
}
}
if (exp.e1.checkScalar() || exp.e1.checkReadModifyWrite(exp.op, exp.e2))
return setError();

int arith = (exp.op == TOK.addAssign || exp.op == TOK.minAssign || exp.op == TOK.mulAssign || exp.op == TOK.divAssign || exp.op == TOK.modAssign || exp.op == TOK.powAssign);
Expand Down
2 changes: 1 addition & 1 deletion test/fail_compilation/diag13320.d
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag13320.d(13): Error: `f += 1` is not a scalar, it is a `Foo`
fail_compilation/diag13320.d(13): Error: `f` is not a scalar, it is a `Foo`
---
*/

Expand Down
18 changes: 18 additions & 0 deletions test/fail_compilation/fail18985.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail18985.d(16): Error: `foo` is not a scalar, it is a `object.Object`
fail_compilation/fail18985.d(17): Error: `bar` is not a scalar, it is a `shared(Object)`
---
*/

// https://issues.dlang.org/show_bug.cgi?id=18985

Object foo;
shared Object bar;

void main()
{
foo += 1;
bar += 1;
}
2 changes: 1 addition & 1 deletion test/fail_compilation/fail3672.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TEST_OUTPUT:
---
fail_compilation/fail3672.d(27): Error: read-modify-write operations are not allowed for `shared` variables. Use `core.atomic.atomicOp!"+="(*p, 1)` instead.
fail_compilation/fail3672.d(31): Error: read-modify-write operations are not allowed for `shared` variables. Use `core.atomic.atomicOp!"+="(*sfp, 1)` instead.
fail_compilation/fail3672.d(31): Error: none of the `opOpAssign` overloads of `SF` are callable for `*sfp` of type `shared(SF)`
---
*/

Expand Down

0 comments on commit ff23072

Please sign in to comment.