www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15271] New: Parameters of final classes become uninitialised


          Issue ID: 15271
           Summary: Parameters of final classes become uninitialised in
                    out contracts with DMD only
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: lt.infiltrator gmail.com

final class C {
   void property(uint rate)
   out {
      assert(_rate == rate, "This will fail");
   } body { _rate = rate; }

   this() { }
   uint _rate;

void main() {
   auto c = new C;
   c.property = 25;

This only fails with DMD. v2.068 for sure; and as far back as 2.065 if memory
serves.  I'm not sure whether it ever worked with DMD.  It works fine with GDC.
 I haven't tested it with LDC.

If the class is made non-final, or the method is made a UFCS function taking C
as the first parameter, then the issue disappears.

Rationale for the "critical" severity: first-class support for unittests and
contracts is one of the big selling points for D.  Therefore, out contracts not
working properly seems like a critical issue.  Feel free to disagree.

Oct 31 2015