[Issue 2437] ICE(tocsym.c, !needThis()) - default struct argument

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Apr 14 07:52:18 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=2437


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #6 from Don <clugdbug at yahoo.com.au> 2010-04-14 07:52:15 PDT ---
The code I've previously posted is definitely incorrect. The problem here is
that the compiler's thinks that the struct is a field of the parent; and this
happens because the scope is wrong.

I'm really not sure where to fix this. One possibility is to add it to
CommaExp::semantic, creating a new scope whenever there's a declaration which
isn't in module scope. But I think the correct solution is to change the scope
for evaluating the default arguments, in mtype.c
around line 4766; 


        /* Create a scope for evaluating the default arguments for the
parameters
         */
        Scope *argsc = sc->push();
        argsc->stc = 0;                 // don't inherit storage class
        argsc->protection = PROTpublic;
+        /* Compiler-generated comma expressions (such as struct constructors)
+         * can include a variable declaration. This declaration needs to go
somewhere.
+         * If we're inside a function, it can become a local variable of that
function;
+         * but if not (for example, if it is a function default parameter), it
needs
+         * its own scope.
+         */
+        if (!argsc->func) // not a nested function
+          argsc->parent = (Dsymbol*)sc->module;

But I don't know if it's OK to set the parent in this way. The cast is needed
only because mtype.c doesn't have the real definition of Module.
The patch to bug 2935 is required in addition to this one.

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


More information about the Digitalmars-d-bugs mailing list