[Mono-bugs] [Bug 518707] New: gmcs fails to unbox 'var' to check it against generic constraints

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Jul 2 09:07:09 EDT 2009


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


           Summary: gmcs fails to unbox 'var' to check it against generic
                    constraints
    Classification: Mono
           Product: Mono: Compilers
           Version: SVN
          Platform: x86
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: skolima at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.1)
Gecko/20090624 Firefox/3.5 (.NET CLR 3.5.30729)

The following code does not compile properly with gmcs 2.0.1, 2.4.2 and
svn-r137273. When the code is compiled with MS.Net and run on Mono, the
expected result is produced. Comparing the IL produced, the gmcs fails to unbox
the Object parameter stored in a 'var' to check it's type against generic Type
parameter.

Reproducible: Always

Steps to Reproduce:
Compile this code with gmcs and run on either Mono or MS.Net:

using System;

namespace Spike
{
    class Program
    {
        static void Main(string[] args)
        {
            Tester<int> t = new Tester<int>();
            Console.WriteLine(t.Get(333));
            Console.WriteLine(t.Get(222.12));
        }

        private class Tester<T> where T : struct, IConvertible
        {
            public T Get(object data)
            {
                var val = data;
                if (val is T)
                    return (T)val;
                return default(T);
            }
        }

    }
}
Actual Results:  
During compilation:
"Program.cs(19,41): warning CS0184: The given expression is never of the
provided
 (`T') type
Program.cs(20,41): warning CS0162: Unreachable code detected
Compilation succeeded - 2 warning(s)"
During execution:
0
0

Expected Results:  
No warnings during compilation.
Execution produces:
333
0

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