2511 – Covariant return type doesn't work with circular import

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2511 - Covariant return type doesn't work with circular import
Summary: Covariant return type doesn't work with circular import
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 blocker
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
Reported: 2008年12月13日 10:21 UTC by Koroskin Denis
Modified: 2014年04月18日 09:12 UTC (History)
4 users (show)

See Also:


Attachments
better detection if a base class is forward referenced (2.87 KB, patch)
2009年09月18日 01:07 UTC, Rainer Schuetze
Details | Diff
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 Koroskin Denis 2008年12月13日 10:21:23 UTC
Here is a sample code that triggers an error:
// File I.d
module I;
import Base;
interface I
{
}
interface SubI : I
{
}
// File Base.d
module Base;
import I;
class Base
{
 I create() {
 return null;
 }
}
class Derived : Base
{
 SubI create() {
 return null;
 }
}
Compilation options: "dmd I.d"
Note that "dmd Base.d" compiles okay.
Comment 1 Koroskin Denis 2008年12月13日 10:22:36 UTC
And here is an error message:
Base.d(15): function Base.Derived.create of type SubI() overrides but is not covariant with Base.Base.create of type I()
Comment 2 Koroskin Denis 2008年12月13日 10:32:11 UTC
The error can fixed by removing "import Base;" from the I.d, but unfortunately I can't do this in my application because interfaces have methods that accept and return references to Base and Derived:
interface I
{
 void doStuff(Base b);
}
interface SubI : I
{
 void doStuff(Derived b);
}
A possible solution is to merge them into a single file (which is not acceptable). You should also have a proper file order to compile them at once:
dmd Base I // okay
dmd I Base // fails to compile
Rising its severity until I find a workaround.
Comment 3 Stewart Gordon 2009年04月13日 16:40:52 UTC
This sounds related to old bug 125. And it occurs in the D1 line too.
Also rewriting the summary line as the one that was there was confusing.
Comment 4 Rainer Schuetze 2009年09月18日 01:07:31 UTC
Created attachment 456 [details] 
better detection if a base class is forward referenced
The current implementation (as of DMD 2.032) defers covariance analysis only if the base class is not yet semantically analysed and it is not an interface. The patch refines this condition by testing whether the class has any forward referenced base classes or interfaces.
Comment 5 Walter Bright 2010年08月27日 22:33:25 UTC
The patch breaks this code:
class UA {
 A29 f() { return null; }
}
class UB : UA {
 B29 f() { return null; }
}
class A29
{
}
class B29 : A29
{
}
Comment 6 Walter Bright 2010年08月27日 22:49:56 UTC
Partial apply of patch:
http://www.dsource.org/projects/dmd/changeset/638 
Comment 7 Rainer Schuetze 2010年08月28日 00:23:08 UTC
Oh, it's only been tested on interfaces. ClassDeclaration::isBaseInfoComplete() is broken, class Object doesn't need a base class:
int ClassDeclaration::isBaseInfoComplete()
{
 if (!baseClass)
 return ident == Id::Object;
...
Comment 8 Walter Bright 2010年08月29日 12:55:08 UTC
This now fails:
class UA {
 A29 f() { return null; }
}
class UB : UA {
 B29 f() { return null; }
}
class A29
{
}
class B29 : A29
{
}
Comment 9 Brad Roberts 2010年08月29日 13:08:40 UTC
NOTE: these tests are part of the dmd svn depot these days.. so if you check it out from dsource you can run them yourself
cd $(dir}/dmd/src
make
cd ../test
make
It's only known to work on linux, though ought to work on any posix system and will need work to work on windows. Any fixes that are required I'd be happy to fold in.
Comment 10 Walter Bright 2010年08月29日 14:31:42 UTC
http://www.dsource.org/projects/dmd/changeset/650 


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