Bug 18744 – Class l-values can be implicitly converted to `Object` l-values, even in safe code

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-04-07T22:01:04Z
Last change time
2023-04-03T14:57:38Z
Keywords
accepts-invalid, safe
Assigned to
No Owner
Creator
David Nadlinger

Comments

Comment #0 by code — 2018-04-07T22:01:04Z
--- @safe: class A { int* a; } class B { long b; } // Either of these shouldn't be allowed: void boom1(ref A a, B b) { (cast(Object)a) = b; } void boom2(ref A a, B b) { (true ? a : b) = b; } int main() { A a = new A; B b = new B; boom1(a, b); boom2(a, b); return *a.a; } --- compiles fine on DMD 2.079, but covariance in l-values can't be allowed. This is the same problem often illustrated using containers.
Comment #1 by razvan.nitu1305 — 2023-04-03T14:57:38Z
Using latest dmd master I get: test2.d(7): Error: `cast(Object)a` is not an lvalue and cannot be modified test2.d(8): Error: conditional expression `true ? cast(Object)a : cast(Object)b` is not a modifiable lvalue So this seems to have been fixed.