[Issue 21033] New: enhancement: allow assign to field when the shared owing object has been locked already without cast
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jul 10 20:59:45 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21033
Issue ID: 21033
Summary: enhancement: allow assign to field when the shared
owing object has been locked already without cast
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: mingwu at gmail.com
```
class A {
SysTime time;
synchronized setTime(ref SysTime t) {
time = t;
}
}
void main() {
shared A a = new A();
SysTime time;
a.setTime(time);
}
```
Same Error: template std.datetime.systime.SysTime.opAssign cannot deduce
function from argument types !()(SysTime) shared, candidates are:
/usr/include/dmd/phobos/std/datetime/systime.d(659,17): opAssign()(auto
ref const(SysTime) rhs)
However, we have a lock on the owning shared object, still we need cast to make
it compile:
```
cast()time = t;
```
I know I can make it work by casting, my question is:
we had a lock on the owning shared object already, WHY we still need the cast
to make it compile.
I think if we enhance the compiler on this simple example, it may cover ~90% of
such use case without the need of the ugly cast.
--
More information about the Digitalmars-d-bugs
mailing list