[Issue 16433] New: __traits(compiles) inconsistent for child class

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Aug 26 04:03:43 PDT 2016


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

          Issue ID: 16433
           Summary: __traits(compiles) inconsistent for child class
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ryan at rcorre.net

---
class Parent {
  int x;
  void fun() { 
    pragma(msg, "Parent method scope: " ~ 
                __traits(compiles, this.x = this.x).stringof); // true
  }
  pragma(msg, "Parent class scope: " ~ 
              __traits(compiles, this.x = this.x).stringof); // true
}

class Child : Parent {
  void dun() { 
    pragma(msg, "Child method scope: " ~ 
                __traits(compiles, this.x = this.x).stringof); // true
  }
  pragma(msg, "Child class scope: " ~ 
              __traits(compiles, this.x = this.x).stringof); // false
}
---

I would expect that the second __traits(compiles) (inside Parent, but outside
any function) would return false, as this.x = this.x is not valid in that
scope.
If it should return true for some reason, presumably that would also be the
case
in the Child.

--


More information about the Digitalmars-d-bugs mailing list