[Mono-bugs] [Bug 627488] New: Generic constraints not (fully?) inherited on virtual generic method override

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Aug 2 11:08:43 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=627488

http://bugzilla.novell.com/show_bug.cgi?id=627488#c0


           Summary: Generic constraints not (fully?) inherited on virtual
                    generic method override
    Classification: Mono
           Product: Mono: Compilers
           Version: SVN
          Platform: x86-64
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: j.bogdoll at gmx.net
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.1.11)
Gecko/20100722 Firefox/3.5.11

When overriding a virtual, generic method with generic constraints which itself
has arguments which are generic and use the method's type parameter(s),
mcs/gmcs/dmcs report error CS0314.

The problem occurs only if the method argument type requires constraints to be
present (i.e. itself has constraints which the method declaration must match),
and if the constraint is a derivation constraint of a generic interface, such
as T : IEquatable<T> or T : IComparable<T>. Other constraints do not cause the
problem.

The virtual method in the base class compiles without problems in the absence
of an override.


Test case:

-------------------------------
using System;

public class GenericType<U> where U : IEquatable<U>
{
  public U u;
}

public class Base
{
  public virtual T Test<T>(GenericType<T> gt) where T : IEquatable<T>
  {
    return gt.u;
  }
}

public class Override: Base
{
  public override T Test<T>(GenericType<T> gt) // This is where the problem is
  {
    throw new NotImplementedException();
  }
}
-------------------------------

In this case, the error received is:
Test.cs(18,35): error CS0314: The type `T' cannot be used as type parameter `U'
in the generic type or method `GenericType<U>'. There is no boxing or type
parameter conversion from `T' to `System.IEquatable<T>'
Test.cs(3,14): (Location of the symbol related to previous error)

When the constraint is added to the override, error CS0460 "Cannot specify
constraints for overrides and explicit interface implementation methods"
occurs, as expected.


Reproducible: Always

Steps to Reproduce:
Compile test case given above for any target framework version that supports
generics.

Actual Results:  
Compilation fails with error CS0314 as described above.

Expected Results:  
Should compile without errors.

Note: I got this error running mono SVN-r160737 on FreeBSD, but I presume this
problem to be OS-indepenent.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list