[Issue 9618] New: DMD takes unnecessary route to alias this in certain situations

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 28 19:21:30 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9618

           Summary: DMD takes unnecessary route to alias this in certain
                    situations
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: puneet at coverify.org


--- Comment #0 from Puneet Goel <puneet at coverify.org> 2013-02-28 19:21:28 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list