www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 852] New: ICE in dmd with anon. delegate in static class ctor in unittest

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

           Summary: ICE in dmd with anon. delegate in static class ctor in
                    unittest
           Product: D
           Version: 1.00
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: daniel.keep+d.puremagic.com gmail.com


Description:

If you attempt to compile code where there is a static constructor which
creates an anonymous delegate which instantiates the class itself, all of which
is in a unit test, with the "-unittest" switch, DMD crashes with an ICE.

Steps to reproduce:

1) Attempt to compile code below with the command "dmd -unittest ice.d".

Actual result:

The following message: "Internal error: toir.c 170"

Expected result:

Either a normal compilation error, or compilation success.

Compiler: Digital Mars D Compiler v1.0, WinXP SP2.

Code to reproduce: (ice.d)

unittest
{
    class Foo
    {
        static this()
        {
            auto i = {return new Foo;};
        }

        this() {}
    }
}

void main() {}


-- 
Jan 17 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=852


thomas-dloop kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|ice-on-valid-code           |





The code isn't legal:











Line 5 requires access to test's context pointer, thus it should fail because 
line 3 can't provide one.
Change "class Foo" to "static class Foo" to sidestep the problem.

Added to DStress as
http://dstress.kuehne.cn/nocompile/b/bug_toir_170_A.d
http://dstress.kuehne.cn/nocompile/b/bug_toir_170_B.d


-- 
Feb 23 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=852


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Keywords|                            |ice-on-invalid-code





Indeed, it compiles if the class is made static.  But why?  Where has it got a
context pointer from?


-- 
Sep 19 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=852


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|ICE(toir.c) in dmd with     |ICE(toir.c) using local
                   |anon. delegate in static    |class in non-static nested
                   |class ctor in unittest      |function in nested static
                   |                            |function





Changed name from ICE(toir.c) in dmd with anon. delegate in static class ctor
in unittest, since it has nothing to do with delegates, static class
constructors, or unittest!

This reduced test case shows that it's caused by use of new of local class,
inside a non-static function nested inside static local function. 

---
void bar() {
    class Foo { }
    static void foo() {
        void pug() {
            Foo z = new Foo; 
        }
    }
}
---

If you move the 'static' from foo to pug, you get the error:

void bar() {
    class Foo { }
    void foo() {
        static void pug() {
            Foo z = new Foo; 
        }
    }
}

ice.d(8): Error: function ice.bar is a nested function and cannot be accessed
fr
om pug
But this seems to be a rejects-valid to me -- I can't see any reason why a
static nested function couldn't access a local class.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=852


Tomas Lindquist Olsen <tomas famolsen.dk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tomas famolsen.dk





04:40:48 PDT ---
It's because the local class is not marked static, and thus needs a reference
to bar's stack frame, which is unreachable from pug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=852






04:46:15 PDT ---
Both test cases work correctly in LDC by giving an error:

$ ldc foo.d
foo.d(5): Error: outer function context of foo.bar is needed to 'new' nested
class foo.bar.Foo

$ ldc foo2.d
foo.d(5): Error: outer function context of foo2.bar is needed to 'new' nested
class foo2.bar.Foo

This is most likely because we moved the error checking out of codegen and into
the frontend (where it belongs).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=852






04:49:17 PDT ---
You can see:

http://dsource.org/projects/ldc/browser/dmd/expression.c#L3589

for details.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=852






Created an attachment (id=383)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=383)
Patch against DMD2.030.

This is simply copied from LDC. It works without modification on DMD2 and DMD1.
(Gives a nicer error message, too).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=852


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
           Severity|minor                       |major




-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=852


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





02:45:07 PDT ---
Fixed dmd 1.046 and 2.031

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