[Issue 18985] bad error message for += operation on shared Object
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jun 15 12:05:03 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18985
RazvanN <razvan.nitu1305 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |razvan.nitu1305 at gmail.com
--- Comment #4 from RazvanN <razvan.nitu1305 at gmail.com> ---
AnyObject foo;
shared AnyObject bar;
void main()
{
foo += 1; /* Error: foo += 1 is not a scalar, it is a object.Object */
bar += 1; /* Error: read-modify-write operations are not allowed for shared
variables. Use core.atomic.atomicOp!"+="(bar, 1) instead. */
}
We can distinguish 4 situations here:
1. AnyObject does not define any opOpAssign methods => error message should be
in both situations "$object is not scalar"
2. Anyobject does define opOpAssign but it's not shared => foo passes
compilation, but bar does not and the most helpful error message would be
"read-modify-write operations are not allowed for shared variables. Use
core.atomic.atomicOp!"+="(bar, 1) instead or implement a shared opOpAssign for
type AnyObject"
3. AnyObject defines opOpAssign shared but not normal opOpAssign => foo += 1
fails with "object is not scalar message" and bar works.
4. AnyObject defines both shared/non-shared opOpAssign => both examples compile
--
More information about the Digitalmars-d-bugs
mailing list