5230 – Regression(2.041, 1.057) ICE(tocsym.c) overriding a method that has an out contract

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5230 - Regression(2.041, 1.057) ICE(tocsym.c) overriding a method that has an out contract
Summary: Regression(2.041, 1.057) ICE(tocsym.c) overriding a method that has an out co...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P1 regression
Assignee: No Owner
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
Reported: 2010年11月17日 09:42 UTC by Stewart Gordon
Modified: 2017年10月01日 20:41 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Stewart Gordon 2010年11月17日 09:42:46 UTC
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 Don 2010年11月17日 11:57:00 UTC
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 Don 2010年11月22日 06:44:54 UTC
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 Don 2010年11月22日 07:00:15 UTC
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.
Comment 4 Walter Bright 2010年12月05日 21:18:47 UTC
http://www.dsource.org/projects/dmd/changeset/783 
Comment 5 github-bugzilla 2017年09月25日 21:23:16 UTC
Commit pushed to stable at https://github.com/dlang/dmd
https://github.com/dlang/dmd/commit/b79c250bc27659274aa3a93473cd8f550738e3ad
Handle bug 3602 and 5230, add tests for them.
Comment 6 github-bugzilla 2017年10月01日 20:41:10 UTC
Commit pushed to master at https://github.com/dlang/dmd
https://github.com/dlang/dmd/commit/b79c250bc27659274aa3a93473cd8f550738e3ad
Handle bug 3602 and 5230, add tests for them.


AltStyle によって変換されたページ (->オリジナル) /