Bug 39370 - CS1061 - Generic function constraint that inherits from another constraint: the latter won't propagate
Summary: CS1061 - Generic function constraint that inherits from another constraint: t...
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-03-04 17:12 UTC by athibodeau
Modified: 2016-03-05 13:58 UTC (History)
1 user (show)

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

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 athibodeau 2016-03-04 17:12:41 UTC
When a generic function constraint inherits from another constraint, the latter is not propagated when compiling and we get a CS1061 error. I have tested with Mono 4.2.2.30 (mcs --version says "Mono C# compiler version 4.2.2.0").

The following example compiles successfully with Visual Studio 2013 (target framework: tested with .NET Framework 4.5 and 2.0), but doesn't compile with Mono.

public class A
{
	public void F()
	{
	}
}

public class B : A
{
}

public class C : B
{
}

class Tester
{
	public void Test()
	{
		GenericF<B, C>(new C());
	}

	private void GenericF<T1, T2>(T2 t2)
		where T1 : B
		where T2 : T1
	{
		t2.F(); // T2 is T1, T1 is B, so T2 is be B and contains F(). CS1061
	}
}
Comment 1 Marek Safar 2016-03-05 13:58:43 UTC
Already fixed in master and Mono 4.4