Bug 6360 - Variance validity issue on contravariant type parameter (CS1961)
Summary: Variance validity issue on contravariant type parameter (CS1961)
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-08-01 15:57 UTC by Ian Battersby
Modified: 2013-01-25 15:51 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Example code showing the compile issue. (724 bytes, application/octet-stream)
2012-08-01 15:57 UTC, Ian Battersby
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Ian Battersby 2012-08-01 15:57:10 UTC
Created attachment 2287 [details]
Example code showing the compile issue.

Finding a compile issue with contravariant usage, assumably a variance checking problem. The following code compiles on .NET without issue, but causes an error compiling from command-line (gmcs).

MONO VERSION:
2.10.9

ERROR:
ContravariantIssue.cs(3,26): error CS1961: The contravariant type parameter `TSomething' must be covariantly valid on `ContravariantIssue.In.Mono.Example.IInterface<TSomething>.Something'

CODE (also attached, alternatively gist: https://gist.github.com/3230065):
namespace ContravariantIssue.In.Mono.Example
{
	public interface IInterface<in TSomething>
	{
		TSomething Something { set; }
	}

	public interface TSomething
	{
		string FieldOne { get; set; }
		string FieldTwo { get; set; }
	}

	public class Something : TSomething
	{
		public string FieldOne { get; set; }
		public string FieldTwo { get; set; }
	}

	public class ContraExample : IInterface<Something>
	{
		public Something Something { private get; set; } 
	}

	class Program
	{
		static void Main(string[] args)
		{

		}
	}
}
Comment 1 Marek Safar 2012-08-02 12:00:34 UTC
Already fixed in Mono 2.11
Comment 2 Ian Battersby 2013-01-25 10:02:25 UTC
When might we see this in a stable release of 2.x? We're now 6 months on from the above ticket, and probably even further since the fix was made :(
Comment 3 Marek Safar 2013-01-25 11:28:32 UTC
This fix is part of Mono 3.0.x release
Comment 4 Ian Battersby 2013-01-25 15:51:04 UTC
Appreciate that Marek (and our CI builds for Mono beta run against this version successfully), unfortunately for those who only want to use a stable release we're stuck pushing them towards a beta version :(