D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4465 - ICE(symbol.c): immutable type inference with ^^2
Summary: ICE(symbol.c): immutable type inference with ^^2
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2010-07-15 06:41 UTC by Lars T. Kyllingstad
Modified: 2010-09-22 17:44 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lars T. Kyllingstad 2010-07-15 06:41:42 UTC
Test case:

    void f()
    {
        int g()
        {
            immutable z = 2^^2;  // or const, doesn't matter
            return z;
        }
    }

Error:

    Internal error: ../ztc/symbol.c 1041

The error message disappears if you
    - make g() return something other than z
    - make z mutable
    - assign z something other than a power expression
Comment 1 Lars T. Kyllingstad 2010-07-15 08:40:25 UTC
Turns out this has nothing to do with the function being nested.  This fails too, with the same error:

    int g()
    {
        immutable z = 2^^2;
        return z;
    }
Comment 2 Don 2010-08-13 03:03:40 UTC
Reduced test case. Doesn't even need a return. It only happens for x^^2 and x^^3,  and that's because those cases become comma expressions. Probably something is wrong in fromConstInitializer().

void bug4465()
{
    const a = 2 ^^ 2;
    int b = a;
}
Comment 3 Don 2010-08-13 12:15:34 UTC
One option would be to change PowExp to stop using CommaExp, but I think that lowering involving comma expressions is such a useful internal feature that it's worth supporting.
---------------
PATCH:
optimize.c, fromConstInitializer(), line 142.

        e = expandVar(result, v);
        if (e)
        {
+            // If it is a comma expression involving a declaration, we mustn't 
+            // perform a copy -- we'd get two declarations of the same variable.
+            // See bugzilla 4465.
+            if (e->op == TOKcomma && ((CommaExp *)e)->e1->op == TOKdeclaration)
+                 e= e1;
+            else
        if (e->type != e1->type && e1->type && e1->type->ty != Tident)
            {   // Type 'paint' operation
                e = e->copy();
Comment 4 Walter Bright 2010-09-22 17:44:54 UTC
http://www.dsource.org/projects/dmd/changeset/685