Bug 9618 – `alias this` is used insted of implicit upcasting of other `alias this` target

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-28T19:21:28Z
Last change time
2018-10-11T16:55:27Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Puneet Goel

Comments

Comment #0 by puneet — 2013-02-28T19:21:28Z
I am using the latest DMD github snapshot. The following reduced code gives me an error on line 4: test.d(4): Error: e2ir: cannot cast b.barObj.val of type int to type test.BarBase The error disappears if I comment out the "alias this" on line 10. As per my analysis, the following conditions must be met for the error to appear. 1. At least one (correct) "alias this" mapping should have already happened. In this example, that mapping is from Bar -> BarObj 2. An implicit upcast is required after the first alias mapping has occurred. In the example that upcast is from BarObj -> BarBase In such situations, DMD is not looking at the possible upcast if further "alias this" is possible. It does (incorrect) mapping to "alias this" and ends up in a compile failure. class Foo(T) { // 1 T a ; // 2 void bind(Bar b) { // 3 this.a = b; // 4 } // 5 } // 6 class BarBase{} // 7 class BarObj: BarBase { // 8 int val; // 9 alias val this; // 10 } // 11 class Bar { // 12 BarObj barObj; // 13 alias barObj this; // 14 } // 15 class Top { // 16 Bar bar; // 17 Foo!(BarBase) foo; // 18 this() { // 19 foo.bind(bar); // 20 } // 21 } // 22
Comment #1 by verylonglogin.reg — 2013-11-09T04:29:02Z
Reduced testcase: --- class C { int val; alias val this; } struct S { C c; alias c this; } void main() { C c1 = S(); // ok Object c2 = S().c; // ok Object c3 = S(); // Error: e2ir: cannot cast (new C2).c.val of type int to type main.Base } ---
Comment #2 by verylonglogin.reg — 2013-11-09T11:14:46Z
A report for e2ir ICE from testcases: Issue 11485
Comment #3 by razvan.nitu1305 — 2018-10-11T16:55:27Z
The code in the original post now compiles with git HEAD. Closing as fixed. Please reopen if you encounter any problems with this.