www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12884] New: implicit conversion wrongly prefers casting

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

          Issue ID: 12884
           Summary: implicit conversion wrongly prefers casting immutable
                    away over alias this when target type is base class
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: ASSIGNED
          Keywords: wrong-code
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nilsbossung googlemail.com
          Reporter: nilsbossung googlemail.com

---
class B {int x;}
class C : B
{
    this(int x) pure {this.x = x;}
     property C mutable() const {return new C(42);}
    alias mutable this;
}
void main()
{
    immutable c = new C(1);
    B m1 = c; /* should call alias this */
    assert(m1.x == 42);
    assert(m1 !is c);
}
---

Pull request is on the way.

--
Jun 09 2014