[Mono-bugs] [Bug 482996] New: Bad type inferencing in LINQ expression

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Mar 6 14:53:32 EST 2009


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


           Summary: Bad type inferencing in LINQ expression
    Classification: Mono
           Product: Mono: Compilers
           Version: SVN
          Platform: x86-64
        OS/Version: openSUSE 11.1
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: jpryor at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


The summary may be bad; not sure how to summarize this other than with code.

In short, this code fails to compile:

  using System.Linq;
  public partial class Product
  {
    public int CategoryID;
    public decimal UnitPrice;
  }
  class MainClass
  {
    public static void Main(string[] args)
    {
      Product[] products = new[]{
        new Product { CategoryID = 1, UnitPrice = 1m },
        new Product { CategoryID = 2, UnitPrice = 2m },
        new Product { CategoryID = 3, UnitPrice = 3m },
        new Product { CategoryID = 4, UnitPrice = 4m },
        new Product { CategoryID = 5, UnitPrice = 5m },
      };
      var categories = from p in products
        group p by p.CategoryID into g
        select new {
          g,
          ExpensiveProducts = from p2 in g
            where (p2.UnitPrice > g.Average(p3 => p3.UnitPrice))
            select p2
        };
    }
  }

It generates the compiler error:

  b.cs(23,23): error CS0019: Operator `>' cannot be applied to operands of type 
  `decimal' and `double'

which is on the line:

            where (p2.UnitPrice > g.Average(p3 => p3.UnitPrice))

I have no idea why it's trying to use `double' in the first place; my guess is
bad type inferencing.

The above code compiles under .NET CSC, and this error prevents the DbLinq unit
tests from building under mono.

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