Bug 15523 - Incorrect base class resolution for generic method with generic return type
Summary: Incorrect base class resolution for generic method with generic return type
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: 3.2.x
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Marek Safar
: 15757 ()
Depends on:
Reported: 2013-10-20 16:48 UTC by Anders Gustafsson
Modified: 2013-11-03 08:03 UTC (History)
2 users (show)

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

Test case highlighting the bug (1.66 KB, text/plain)
2013-10-20 16:48 UTC, Anders Gustafsson

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:

Description Anders Gustafsson 2013-10-20 16:48:28 UTC
Created attachment 5185 [details]
Test case highlighting the bug

If I have an inheritance hierarchy like this: -

    public class GrandBase
    public class Base : GrandBase
    public class Derived : Base

define a virtual method with a signature like this in `GrandBase`: -

    public virtual T Foo<T>()

override the method in both `Base` and `Derived`, and in the `Derived` method override call `base.Foo` with a specific type: -


Then, it is not the most derived implementation of `Foo` that is being called (C# Language Specification §7.6.8), but the *least* derived implementation, i.e. `GrandBase.Foo`.

As far as I can tell, it is only under these specific circumstances that the wrong implementation in the inheritance hierarchy is called. If `Foo` returns a specific type or void, or if `Derived.Foo` calls `base.Foo<T>()`, the correct implementation, i.e. `Base.Foo` will be called.

Attached is a test case that should clarify the issue.

The code has been built with Xamarin Studio 4.0 on both Windows and Mac with the same result. On Windows, running with the Mono and .NET runtimes yield the same result.

The issue has also been raised at StackOverflow, http://stackoverflow.com/q/19449720/650012
Comment 1 Anders Gustafsson 2013-10-24 10:43:22 UTC
Any news on this?

To facilitate evaluation, here is the critical code lined up.

	public class GrandBase {
		public virtual T GenericReturnType<T>() {
			return default(T);

	public class Base : GrandBase {
		public override T GenericReturnType<T>() {
			return default(T);

	public class Derived : Base {
		public override T GenericReturnType<T>() {
			base.GenericReturnType<string> ();
			return default(T);

When executing:

	new Derived().GenericReturnType();

The output *should* be:


But currently it *is*:

Comment 2 Marek Safar 2013-10-25 06:26:54 UTC
Fixed in master
Comment 3 Marek Safar 2013-11-03 08:03:28 UTC
*** Bug 15757 has been marked as a duplicate of this bug. ***