www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16579] New: ReturnStatement[CallExp(DotVarExp)]: Corrupted

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

          Issue ID: 16579
           Summary: ReturnStatement[CallExp(DotVarExp)]: Corrupted runtime
                    on missed manifest constant propagation
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

Probably related to issue 16576, if not identical (just another angle of the
same issue).

Working example:
---
struct Thing
{
    enum Instance = Thing();
    int a = 42;

    void iter()
    {
        import std.stdio;
        writeln(this.a);   // Prints "42"
    }
}

void main()
{
    Thing.Instance.iter;
}
---

Broken example:
---
struct Thing
{
    enum Instance = Thing();
    int a = 42;

    void iter()
    {
        import std.stdio;
        writeln(this.a);   // Prints "0"
    }
}

void main()
{
    return Thing.Instance.iter;   // Added 'return'
}
---


In the bad code, the frontend gives us a CallExp for:

   Instance.iter()

In the good code, the frontend gives us a CallExp for:

   Thing().iter()

So it looks on the surface that constfold has missed a case where it should
have propagated the manifest 'Instance' into a literal 'Thing()'.

--
Oct 03 2016