Jump to page: 1 2
Thread overview
[Issue 3602] New: cannot compile a class, if its super class has preconditions
Dec 08, 2009
Qian Xu
Dec 08, 2009
Qian Xu
[Issue 3602] ICE(tocsym.c) compiling a class, if its super class has preconditions
Jan 27, 2010
Don
Apr 03, 2010
Robert Clipsham
Jun 15, 2010
Stewart Gordon
Jun 15, 2010
Don
Jun 15, 2010
Stewart Gordon
Jun 15, 2010
Stewart Gordon
Sep 15, 2010
Don
Sep 22, 2010
Walter Bright
December 08, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3602

           Summary: cannot compile a class, if its super class has
                    preconditions
           Product: D
           Version: 1.051
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: qian.xu@funkwerk-itk.com


--- Comment #0 from Qian Xu <qian.xu@funkwerk-itk.com> 2009-12-08 08:44:14 PST ---
Dear Developers,

I see an error message while dmd tries to compile a class:

========= ERROR =========
Box.d(7): Error: function __require forward declaration
linkage = 0
dmd: tocsym.c:381: virtual Symbol* FuncDeclaration::toSymbol(): Assertion `0'
failed.
Aborted
========= ERROR =========



dmd: tocsym.c:381: virtual Symbol* FuncDeclaration::toSymbol(): Assertion `0'
failed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 08, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3602



--- Comment #1 from Qian Xu <qian.xu@funkwerk-itk.com> 2009-12-08 08:49:26 PST ---
Sorry for the first commit. The description is incomplete.

Now the part 2:

I have two classes as follows:

====== FILE: Box.d ======
module Box;
class Box {
   void paint(int x, int y)
   in {
       assert(x > 0);
       assert(y > 0);
   }
   body {
   }
}
====== FILE: Box.d ======

====== FILE: ImageBox.d ======
module ImageBox;
class ImageBox: Box {
   void override paint(int x, int y)
   in {
       assert(x > 0);
       assert(y > 0);
   }
   body {
   }
}
====== FILE: ImageBox.d ======

I compile the Box.d using "dmd -w -debug -inline -version=Posix -version=Tango
Box.d -c", it works.
And then I compile the ImageBox.d using "dmd -w -debug -inline -version=Posix
-version=Tango ImageBox.d -c", the dmd compile returns an error.
========= ERROR =========
Box.d(7): Error: function __require forward declaration
linkage = 0
dmd: tocsym.c:381: virtual Symbol* FuncDeclaration::toSymbol(): Assertion `0'
failed.
Aborted
========= ERROR =========


Note that if I write "private" before this method paint, it works.


I think this issue is pretty critical, now I have to remove all preconditions in my super classes.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3602



--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-01-27 00:46:38 PST ---
This is crashing because the contracts are implemented as functions fdrequire,
fdensure, which are NESTED functions of the function ('paint()') being called.
fdrequire->semantic() and fdensure->semantic() need to be run before code
generation of the overridden function.

Because they're nested functions, fdrequire->semantic() is called when running
semantic3() on 'box.paint()'.
But, if because box.paint() was only imported, box.paint()->semantic3() never
gets run!

To fix the bug, we need to make sure that fdrequire->semantic() does get called sometime before code generation. I've tried running it immediately after fdrequire is created; that allows the test case to compile when the two modules are compiled separately, but it causes a different ICE when they are compiled together. I also tried running semantic() from inside mergeRequire(), but I wasn't successful.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 03, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3602


Robert Clipsham <robert@octarineparrot.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |robert@octarineparrot.com


--- Comment #3 from Robert Clipsham <robert@octarineparrot.com> 2010-04-03 13:18:21 BST ---
*** Issue 4055 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3602


Stewart Gordon <smjg@iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
           Platform|Other                       |All
         OS/Version|Linux                       |All
           Severity|critical                    |regression


--- Comment #4 from Stewart Gordon <smjg@iname.com> 2010-06-14 18:30:05 PDT ---
The given testcase is invalid.  However, by fixing the errors, it's reproducible under Windows:

----- imagebox.d -----
module imagebox;
import box;

class ImageBox: Box {
   override void paint(int x, int y)
   in {
       assert(x > 0);
       assert(y > 0);
   }
   body {
   }
}
----- box.d -----
module box;
class Box {
   void paint(int x, int y)
   in {
       assert(x > 0);
       assert(y > 0);
   }
   body {
   }
}
----------
C:\Users\Stewart\Documents\Programming\D\Tests\bugs\bz3602>dmd -c imagebox.d
box.d(5): Error: function __require forward declaration
linkage = 0
Assertion failure: '0' on line 381 in file 'tocsym.c'

abnormal program termination
----------

This has broken SDWF.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3602



--- Comment #5 from Don <clugdbug@yahoo.com.au> 2010-06-15 00:00:53 PDT ---
(In reply to comment #4)
> The given testcase is invalid.  However, by fixing the errors, it's reproducible under Windows.

?? I had no trouble reproducing it under Windows.
Until around DMD 1.050, it used to compile, but that was only because contract
inheritance was silently ignored. This code has never worked properly. OTOH I
agree that it has the importance of a regression.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3602



--- Comment #6 from Stewart Gordon <smjg@iname.com> 2010-06-15 01:39:17 PDT ---
(In reply to comment #5)
> (In reply to comment #4)
> > The given testcase is invalid.  However, by fixing the errors, it's reproducible under Windows.
> 
> ?? I had no trouble reproducing it under Windows.
> Until around DMD 1.050, it used to compile, but that was only because contract
> inheritance was silently ignored. This code has never worked properly. OTOH I
> agree that it has the importance of a regression.

That's very weird.  How did it use to handle the fact that Box is an undefined symbol in ImageBox.d?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3602


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #7 from bearophile_hugs@eml.cc 2010-06-15 02:47:30 PDT ---
I have not seen the ICE but this asserts (v2.047 with warnings):


class A {
   void foo(int x)
       in {
           assert(x > 0); // asserts
       } body {}
}
class B : A {
   override void foo(int y) {}
}
void main() {
    auto b = new B;
    b.foo(10);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3602



--- Comment #8 from Stewart Gordon <smjg@iname.com> 2010-06-15 02:52:55 PDT ---
(In reply to comment #7)
>            assert(x > 0); // asserts

Could hardly state the obvious more - unless there was something else you meant to say....

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 15, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3602


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

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


--- Comment #9 from Don <clugdbug@yahoo.com.au> 2010-09-15 05:15:58 PDT ---
PATCH: func.c, line 1658, FuncDeclaration::mergeFrequire()
----------------

    for (int i = 0; i < foverrides.dim; i++)
    {
        FuncDeclaration *fdv = (FuncDeclaration *)foverrides.data[i];
+        /* The semantic pass on the contracts of the overridden functions must
+         * be completed before code generation occurs (bug 3602).
+        */
+        if (fdv->fdrequire && fdv->fdrequire->semanticRun !=
PASSsemantic3done)
+        {
+            assert(fdv->scope);
+            fdv->semantic3(fdv->scope);
+        }
        sf = fdv->mergeFrequire(sf);
        if (fdv->fdrequire)
        {
            //printf("fdv->frequire: %s\n", fdv->frequire->toChars());

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2