[Mono-list] Custom LINQ query fails to compile - "type arguments cannot be inferred from usage"

m4dc4p jgbailey at gmail.com
Mon Jan 31 19:22:03 EST 2011


The below program fails to compile under Mono 2.8.2.0, but compiles fine with
Microsoft's C# compiler (4.0.30319.1). When I try to compile with dmcs, I
get:

> dmcs /noconfig Program.cs /target:exe
> /reference:/usr/local/lib/mono/4.0/System.Core.dll

Program.cs(12,33): error CS0411: The type arguments for method
`System.Linq.Enumerable.Where<TSource>(this
System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)'
cannot be inferred from the usage. Try specifying the type arguments
explicitly
Program.cs(12,44): error CS0029: Cannot implicitly convert type `string' to
`bool'

I am using the rewrite rules defined the C# 3.0 spec to implement a custom
LINQ translation. It doesn't seem to be anything too weird and I'm baffled
why Mono is complaining

Can anyone help? Thanks in advance!

=== cut here ====

using System;
using System.Linq;

namespace MonoLinq
{
    class Program
    {
        static void Main(string[] args)
        {
            var server = new Server<int>();
            var outputExpr1 = from item in server
                                where item.Is()
                                select item;

            var foo = server.Where(p => p.Is());

            Console.WriteLine("outputExpr1.GetType: {0}",
outputExpr1.GetType().FullName);
            Console.WriteLine("foo.GetType: {0}", foo.GetType().FullName);
        }
    }

    class Server<T>
    {
        public Server()
        {
        }

        public string Where(Func<IDAccessor, string> idExpr)
        {
            return String.Empty;
        }
    }

    class IDAccessor
    {
    }

    static class IDAccessorExt
    {
        public static string Is(this IDAccessor __)
        {
            return null;
        }
    }

}

-- 
View this message in context: http://mono.1490590.n4.nabble.com/Custom-LINQ-query-fails-to-compile-type-arguments-cannot-be-inferred-from-usage-tp3250221p3250221.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list