www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6817] New: [CTFE] Error on interpreting inlined IfStatement

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6817

           Summary: [CTFE] Error on interpreting inlined IfStatement
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dawg dawgfoto.de



struct S
{
    int bug()
    {
        bool b;

        void toggle()
        {
            if (b)
                b = false;
        }

        void trigger()
        {
            toggle();
        }

        trigger();
        return 0;
    }
}

enum interpret = S().bug();

----

When compiling with -inline this gives the following error.
bug.d(9): Error: integral constant must be scalar type, not void.

This happens because the IfStatement gets rewritten to an
AndAndExp during inlining. The AndAndExp is given the type void
which seems reasonable as it is a statement.
Later during interpretation the condition evaluates to true and
an IntegerExp with AndAndExp's type (void) is created, which causes the error.

I can't think of any && expression that doesn't have a bool result,
so using bool for the Integer could be a fix.

One thing that seems a little strange is that it is
the interpretation that actually triggers inlining (through calling semantic3
on the nested function). This inverts the usual order and could possibly
expose more bugs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 16 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6817


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



13:07:51 PDT ---
https://github.com/D-Programming-Language/dmd/commit/3055cc6a8b36a2e00c270b0e48e1d1bd2c931f37

https://github.com/D-Programming-Language/dmd/commit/72e750209b370b66157f320d3517c5816a3951d7

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