[Mono-devel-list] overriding return type

alan jenkins Alan.Jenkins at phonecoop.coop
Sun Jul 27 12:12:40 EDT 2003


>> I guess this thread is finished then
<cringe>

I have examined the compiler source, and the only thing which prevents the use 
of covariant return types is
 
mcs/class.cs(2316) : void Method.CheckBase(TypeContainer container)

It is trivial to alter the method to allow covariant return types, and only 
complain when the return type of the overriding method can't be implicity 
cast to the original return type.  This doesn't seem to break anything - the 
class library compiles fine using the modified compiler.  Assemblies 
containing methods with covariant return types (compiled with the modified 
compiler) can be referenced from assemblies compiled with the original 
compiler (e.g. mono_new covariant.cs; mono_old -r covariant.exe old.cs).

As an alternative to requiring an option to enable it, it might be better to 
have the feature enabled by default, but emit warnings about the portability 
of the C# code when covariant return types are encountered.

I ask the list again:  would you be willing to see the compiler changed in 
such a way?  It appears to be a trivial piece of code which would break 
nothing.

Um... I think I could write the patch myself - it'd only be about 20 lines of 
code in the compiler, plus a test, but I am an absolute C# & Mono newbie.  
Though I would like to think I could work with large projects without 
stepping on other peoples toes, I haven't actually contributed to a project 
before.



More information about the Mono-devel-list mailing list