[Mono-bugs] [Bug 475860] New: C# compiler reports error CS1501 for code that should compile without errors.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Feb 13 16:26:22 EST 2009


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


           Summary: C# compiler reports error CS1501 for code that should
                    compile without errors.
    Classification: Mono
           Product: Mono: Compilers
           Version: unspecified
          Platform: Macintosh
        OS/Version: Mac OS X 10.5
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: dmitchell at logos.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1

Compiling the file listed below results in error CS1501 with gmcs
-target:library, but it works fine with csc (csc does provide a few warnings,
but it has no errors).

---


using System;

namespace MonoBug
{
    public abstract class Reference :
        IEquatable<Reference>,
        IComparable<Reference>,
        IComparable<ReferencePoint>,
        IComparable<ReferenceRange>
    {
        public abstract bool Equals(Reference other);
        public int CompareTo(Reference other)
        {
            if (other == null)
                return 1;
            var otherRange = other as ReferenceRange;
            if (otherRange != null)
                return CompareTo(otherRange);
            else
                return CompareTo((ReferencePoint)other);
        }

        public abstract int CompareTo(ReferencePoint other);
        public abstract int CompareTo(ReferenceRange other);
    }

    public class ReferenceRange : Reference, IEquatable<ReferenceRange>
    {
        public override bool Equals(Reference other)
        {
            return Equals(other as ReferenceRange);
        }

        public bool Equals(ReferenceRange other)
        {
            return Start.Equals(other.Start) && End.Equals(other.End);
        }

        public override int CompareTo(ReferencePoint other)
        {
            if (other == null)
                return 1;
            return -other.CompareTo(this);
        }

        public override int CompareTo(ReferenceRange other)
        {
            if (other == null)
                return 1;

            int nCompare = Start.CompareTo(other.Start);
            if (nCompare == 0)
                nCompare = End.CompareTo(other.End);

            return nCompare;
        }

        public ReferencePoint Start { get { return _start; } }
        public ReferencePoint End { get { return _end; } }

        ReferencePoint _start;
        ReferencePoint _end;
    }

    public class ReferencePoint : Reference, IEquatable<ReferencePoint>
    {
        public override bool Equals(Reference other)
        {
            return Equals(other as ReferencePoint);
        }

        public bool Equals(ReferencePoint other)
        {
            if (other == null)
                return false;
            return _value == other._value;
        }

        public override int CompareTo(ReferencePoint other)
        {
            return _value.CompareTo(other._value);
        }

        public override int CompareTo(ReferenceRange other)
        {
            if (other == null)
                return 1;

            int nCompare = CompareTo(other.Start);
            if (nCompare == 0)
                nCompare = -1;
            return nCompare;
        }

        int _value;
    }
}


Reproducible: Always

Steps to Reproduce:
1. Put the code listed above into a cs file
2. Run "gmcs -target:library your-file.cs" at a command prompt
Actual Results:  
gmcs reports error CS1501 for the call to CompareTo that occurs within
ReferencePoint.CompareTo(ReferenceRange other)

Expected Results:  
gmcs should output a library with no errors.

I have encountered similar errors with other method overloading/overriding
scenarios, particularly with GetHashCode, operator==, and others. Explicitly
upcasting the object on which the method is called often works around the
issue, but it occasionally causes runtime errors.

-- 
Configure bugmail: https://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