Bug 12884 – implicit conversion wrongly prefers casting immutable away over alias this when target type is base class
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-06-09T22:37:00Z
Last change time
2014-06-16T02:32:57Z
Keywords
wrong-code
Assigned to
nilsbossung
Creator
nilsbossung
Comments
Comment #0 by nilsbossung — 2014-06-09T22:37:01Z
---
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.
With class types, the possibility of implicit class reference conversion from derived D to base class B is always determined in type system.
In other words, conversion from immutable D to mutable B is a defined but disabled by default, and 'alias this' cannot override it.
(Note that 'alias this' is invoked when the conversion is _not_ defined)
So, 'alias this' never be considered in the case, and this is invalid issue.