[Issue 3180] New: Need delegate covariance and contravariance
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jul 15 09:15:54 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3180
Summary: Need delegate covariance and contravariance
Product: D
Version: unspecified
Platform: Other
OS/Version: Windows
Status: NEW
Keywords: spec
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: rayerd.wiz at gmail.com
import std.stdio;
class A {}
class B : A {}
class X
{
A foo() { return new A; }
}
class Y : X
{
B foo() { return new B; }
}
class V
{
void foo(B){}
}
void main()
{
// Class Covariance (supported already)
{
X x = new X;
Y y = new Y;
A r = x.foo();
A s = y.foo();
B t = y.foo();
writeln(r); // A
writeln(s); // B
writeln(t); // B
}
// Delegate Covariance
{
A delegate() f = delegate A() { return new A; }; // Of course, OK.
writeln(f()); // A
//A delegate() g = delegate B() { return new B; }; // Need support the
covariance
//writeln(g()); // This should be B.
}
// Delegate Contravariance
{
V v = new V;
void delegate(B) g = &v.foo; // Of course, OK.
//void delegate(A) f = &v.foo; // Need suport the contravariance.
}
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list