[Mono-dev] Covariance, contravariance and name hiding

Marek Safar marek.safar at gmail.com
Tue Feb 22 09:00:43 EST 2011


Hello,

Could you please fill a bug report

Thanks
Marek
> Hi!
> I have the following code:
> ===begin source code===
> interface InterfaceWithCovariance<out TException>
> where TException: Exception
> {
> 	TException Error { get; }
> }
> interface InterfaceWithContravariance<in TException>:
> InterfaceWithCovariance<Exception>
> where TException : Exception
> {
> 	new TException Error{set;}
> }
> ===end source code===
> Microsoft csc.exe compiles this code successfully, because Error  property
> from InterfaceWithCovariance is get_Error method, and Error property from
> InterfaceWithContravariance is set_Error method. But Mono compiler emits the
> following error:
> The contravariant type parameter `TException' must be covariantly valid on
> `ClassLibrary1.InterfaceWithContravariance<TException>.Error' (CS1961)
> I think, this error is occured because compiler use property name when
> analyze covariance/contravariance instead of property accessor method.
>
> Thanks.



More information about the Mono-devel-list mailing list