digitalmars.D.bugs - [Issue 4000] New: Function pointer/delegate covariance
- d-bugmail puremagic.com (49/49) Mar 22 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4000
- d-bugmail puremagic.com (14/14) Jun 08 2011 http://d.puremagic.com/issues/show_bug.cgi?id=4000
http://d.puremagic.com/issues/show_bug.cgi?id=4000 Summary: Function pointer/delegate covariance Product: D Version: future Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc http://msdn.microsoft.com/en-us/library/ms173174%28VS.80%29.aspx class Mammals {} class Dogs : Mammals {} class Program { public delegate Mammals HandlerMethod(); public static Mammals FirstHandler() { return null; } public static Dogs SecondHandler() { return null; } static void Main() { HandlerMethod handler1 = FirstHandler; HandlerMethod handler2 = SecondHandler; } } This is a possible translation to D2: class Mammals {} class Dogs : Mammals {} alias Mammals function() HandlerMethod; Mammals function() handler; Mammals FirstHandler() { return null; } Dogs SecondHandler() { return null; } void main() { HandlerMethod handler1 = &FirstHandler; HandlerMethod handler2 = &SecondHandler; // line 9, err handler = &SecondHandler; // line 10, err } But the D2 code gives two compile errors: test.d(9): Error: cannot implicitly convert expression (& SecondHandler) of type Dogs function() to Mammals function() test.d(10): Error: cannot implicitly convert expression (& SecondHandler) of type Dogs function() to Mammals function() It can be positive for the D type system to accept this code too. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 22 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4000 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |yebblies gmail.com Resolution| |DUPLICATE I'm going to mark this as a dupe of 3180, along with 3833, as both cases are covered by covariance. *** This issue has been marked as a duplicate of issue 3180 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 08 2011