Bug 5230 – Regression(2.041, 1.057) ICE(tocsym.c) overriding a method that has an out contract
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-11-17T09:42:46Z
Last change time
2017-10-01T20:41:10Z
Keywords
ice-on-valid-code, patch
Assigned to
No Owner
Creator
Stewart Gordon
Comments
Comment #0 by smjg — 2010-11-17T09:42:46Z
Clearly the implementation of out contract inheritance is broken.
----- override_out_a.d -----
import override_out_b;
class Derived : Base {
override int method() { return 69; }
}
----- override_out_b.d -----
class Base {
int method()
out (r) {}
body { return 42; }
}
----- DMD 1.065 -----
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd override_out_a.d
override_out_b.d(3): Error: function __ensure forward declaration
linkage = 0
Assertion failure: '0' on line 381 in file 'tocsym.c'
abnormal program termination
----- DMD 2.050 -----
C:\Users\Stewart\Documents\Programming\D\Tests\bugs>dmd override_out_a.d
override_out_b.d(3): Error: function __ensure forward declaration
linkage = 0
Assertion failure: '0' on line 407 in file 'tocsym.c'
abnormal program termination
----------
Compiles successfully if the out contract is removed, or Base and Derived are defined in the same module.
Adding an out contract to Derived.method doesn't change things.
This has broken SDWF.
Comment #1 by clugdbug — 2010-11-17T11:57:00Z
This was almost certainly caused by the fix to
bug 3602: ICE(tocsym.c) compiling a class, if its super class has preconditions
Which had almost exactly the same symptoms as this bug (only with __require instead of __ensure).
Comment #2 by clugdbug — 2010-11-22T06:44:54Z
Exactly the same fix for bug 3602 works here, applied to fensure instead of frequire:
PATCH: func.c, mergeFensure(), line 1728
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 and 5230).
+ */
+ if (fdv->fdensure && fdv->fdensure->semanticRun != PASSsemantic3done)
+ {
+ assert(fdv->scope);
+ fdv->semantic3(fdv->scope);
+ }
sf = fdv->mergeFensure(sf);
Comment #3 by clugdbug — 2010-11-22T07:00:15Z
Actually this needs the patch to bug 5145 applied as well.
I'm not sure which D1 regression this dates from. 1.057 was the first one with an ICE.
But 1.050 - 1056 gave this error:
override_out_a.d(1760): Error: function __ensure (int) does not match parameter types ()
override_out_a.d(1760): Error: expected 1 arguments, not 0
and earlier versions of D1 accepted it, but it didn't work.