www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3602] New: cannot compile a class, if its super class has preconditions

reply d-bugmail puremagic.com writes:
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



---
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: -------
Dec 08 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3602




---
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: -------
Dec 08 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3602




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: -------
Jan 27 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3602


Robert Clipsham <robert octarineparrot.com> changed:

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



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: -------
Apr 03 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jun 14 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3602





 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: -------
Jun 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3602






 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: -------
Jun 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3602


bearophile_hugs eml.cc changed:

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



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: -------
Jun 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3602





            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: -------
Jun 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3602


Don <clugdbug yahoo.com.au> changed:

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



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: -------
Sep 15 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3602


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



06:24:00 PDT ---
http://www.dsource.org/projects/dmd/changeset/683

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