[Mono-bugs] [Bug 327504] New: gmcs gives CS0554 where Microsoft compiler doesn't

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Sep 22 14:20:57 EDT 2007


https://bugzilla.novell.com/show_bug.cgi?id=327504

           Summary: gmcs gives CS0554 where Microsoft compiler doesn't
           Product: Mono: Compilers
           Version: 1.2
          Platform: i686
               URL: http:///
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: rharinath at novell.com
        ReportedBy: jbytheway at gmail.com
         QAContact: mono-bugs at ximian.com
          Found By: Development


Created an attachment (id=174032)
 --> (https://bugzilla.novell.com/attachment.cgi?id=174032)
Source code demonstrating problem

Description of Problem:

When trying to define an implicit conversion operator to a constrained generic
type parameter from its base class as follows (full example in attached
test.cs):

class Base<T>
  where T : Base<T>
{
  public static implicit operator T(Base<T> t)
  {
    return (T) t;
  }
}

gmcs does not allow this operator, where the Microsoft compiler does.  The
error message indicates that it's because Base<T> is a base class of T, which
is true, but apparently this shouldn't matter for a type parameter.  (As an
aside, this operator is useful to have when one is exploiting the "curiously
recurring template pattern".  Also, note that if the type constraint on T is
removed then the code compiles, but then there's nothing to stop T inheriting
from Base<T> all the same.)


Steps to reproduce the problem:
1. run "gmcs test.cs"


Actual Results:

Error as follows:

$ gmcs test.cs 
test.cs(5,26): error CS0554: User-defined conversion `Base<T>.implicit operator
T(Base<T>)' cannot convert to or from derived class
Compilation failed: 1 error(s), 0 warnings


Expected Results:

Successful compilation.


How often does this happen? 

Always.


Additional Information:

Using mono packages from Debian testing.  In particular, mono-gmcs
package version 1.2.5-3.

$ gmcs --version
Mono C# compiler version 1.2.5.0

I haven't compiled this exact code with the Microsoft compiler, so I can't
guarantee that it works, but I've compiled analogous examples successfully.


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


More information about the mono-bugs mailing list