D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6817 - [CTFE] Error on interpreting inlined IfStatement
Summary: [CTFE] Error on interpreting inlined IfStatement
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-16 03:55 UTC by Martin Nowak
Modified: 2011-11-02 13:07 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2011-10-16 03:55:16 UTC
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.