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

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

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

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).


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 :(

Note You need to log in before you can comment on or make changes to this bug.