210 – Strange results when covariantly implementing an interface method defined with an interface return type

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 210 - Strange results when covariantly implementing an interface method defined with an interface return type
Summary: Strange results when covariantly implementing an interface method defined wit...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords: wrong-code
Depends on:
Blocks: 179
Show dependency tree / graph
Reported: 2006年06月19日 10:14 UTC by Stewart Gordon
Modified: 2014年02月15日 13:18 UTC (History)
0 users

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 2006年06月19日 10:14:31 UTC
This bug carries on where issue 65 left off. That issue covered the case where the interface-to-class covariance is in a class-to-class override. This one covers interface-to-class covariance in an interface-to-class override.
This was originally intended to be part of issue 65, but I figured that it might make more sense to break it off as a separate issue.
Testcases, based on issue 179 comment 1:
----------
import std.stdio;
interface Father {
 Father test();
 void showData();
}
class Child : Father {
 int data;
 this(int d) { data = d; }
 Child test() { 
 writefln("in CovFunc Test");
 return new Child(69);
 }
 void showData() {
 writefln("Child: %d", data);
 }
}
void icov2test() {
 Child aChild = new Child(42);
 aChild.showData();
 Father childsDad = aChild;
 childsDad.showData();
 Father dadTest = childsDad.test;
 writefln("FCALL dadTest.showData");
 dadTest.showData();
 writefln("FCALL dadTest.test");
 dadTest.test();
 writefln("FCALL (cast(Child) dadTest).showData");
 (cast(Child) dadTest).showData();
}
----------
import std.stdio;
interface IFoo {
}
interface ICov {
 IFoo covfunc();
}
class Child : ICov, IFoo {
 Child covfunc() { 
 writefln("in CovFunc Test");
 return new Child();
 }
}
void icov3() {
 ICov icov = new Child();
 IFoo ifoo = icov.covfunc();
 writefln(ifoo.classinfo.name); // Segfault or prints garbage
 writefln((cast(Object) ifoo)); // Segfault or prints garbage
}
----------
import std.stdio;
interface IFoo {
 IFoo covfunc();
}
class Child : IFoo {
 Child covfunc() { 
 writefln("in CovFunc Test");
 return new Child();
 }
}
void icov3() {
 IFoo icov = new Child();
 IFoo ifoo = icov.covfunc();
 writefln(ifoo.classinfo.name);
 writefln((cast(Object) ifoo));
}
----------
There are other cases to test, namely those involving interface-to-interface covariance || an interface-to-interface override. But getting the above tests working would be a start.
Comment 1 Walter Bright 2006年06月30日 20:31:46 UTC
Fixed DMD 0.162


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