[Mono-bugs] [Bug 396699] New: gmcs fails to compile nullable user defined binary operators

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Jun 3 09:11:54 EDT 2008


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


           Summary: gmcs fails to compile nullable user defined binary
                    operators
           Product: Mono: Compilers
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: msafar at novell.com
        ReportedBy: jbevain at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Test case that compiles with csc:

<<<<<<<<<<<
using System;

struct Foo {

        public int Value;

        public Foo (int value)
        {
                this.Value = value;
        }

        public static Foo operator + (Foo? a, Foo? b)
        {
                if (a.HasValue && b.HasValue)
                        return new Foo (a.Value.Value + b.Value.Value);

                return new Foo (42);
        }
}

struct Bar {

        public int Value;

        public Bar (int value)
        {
                this.Value = value;
        }

        public static Bar? operator + (Bar? a, Bar? b)
        {
                if (a.HasValue && b.HasValue)
                        return new Bar (a.Value.Value + b.Value.Value);

                return null;
        }
}

class Test {

        static Foo AddFoo (Foo a, Foo b)
        {
                return a + b;
        }

        static Foo AddFooNullable (Foo? a, Foo? b)
        {
                return a + b;
        }

        static Bar? AddBarNullable (Bar? a, Bar? b)
        {
                return a + b;
        }

        static Bar? AddBar (Bar a, Bar b)
        {
                return a + b;
        }

        static int Main ()
        {
                if (AddFooNullable (null, null).Value != 42)
                        return 1;

                if (AddFoo (new Foo (2), new Foo (2)).Value != 4)
                        return 2;

                if (AddBarNullable (null, null) != null)
                        return 3;

                if (AddBar (new Bar (2), new Bar (2)).Value.Value != 4)
                        return 4;

                Console.WriteLine ("OK");
                return 0;
        }
}
>>>>>>>>>>>>>>


-- 
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