March 22, 2010 [Issue 4000] New: Function pointer/delegate covariance | ||||
---|---|---|---|---|
| ||||
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 --- Comment #0 from bearophile_hugs@eml.cc 2010-03-22 07:11:14 PDT --- This page about C#: http://msdn.microsoft.com/en-us/library/ms173174%28VS.80%29.aspx contains this working C# code: 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: ------- |
June 09, 2011 [Issue 4000] Function pointer/delegate covariance | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | 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 --- Comment #1 from yebblies <yebblies@gmail.com> 2011-06-08 22:48:58 PDT --- 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: ------- |
Copyright © 1999-2021 by the D Language Foundation