www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16433] New: __traits(compiles) inconsistent for child class

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 puremagic.com
          Reporter: ryan 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.

--
Aug 26 2016