[Mono-bugs] [Bug 429038] New: Lambda / anon-function incorrectly reports CS1662/ CS0029 for trivial case

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Sep 23 04:21:31 EDT 2008


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


           Summary: Lambda / anon-function incorrectly reports CS1662/CS0029
                    for trivial case
           Product: Mono: Compilers
           Version: unspecified
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: marc.gravell at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Community User


A trivial anon-function/lambda (i.e. no cast required - neither implicit nor
implicit) generates an invalid cast compiler error.

Steps to reproduce the problem:
Code as below, compile with gmcs (note; works fine with csc):

using System;
delegate TResult Getter<TArg, TResult>(TArg value);

public static class Program {
  static void Main() {
    var func = CreatePassThru1<string>();
    Console.WriteLine(func("Hello world"));
  }

  // using named method: works
  static Getter<T,T> CreatePassThru1<T>()
  {
    return PassThru<T>;
  }
  static T PassThru<T>(T value) {return value;}

  // using lambda: fails
  static Getter<T,T> CreatePassThru2<T>()
  {
    return (T value) => value;
  }  
  // anonymous method: fails 
  static Getter<T,T> CreatePassThru3<T>()
  {
    return delegate (T value) { return value;};
  }
}

Actual Results:
test.cs(22,25): error CS0029: Cannot implicitly convert type `T' to `T'
test.cs(22,25): The generic parameter `T' of `Program.CreatePassThru2<T>()'
cann
ot be converted to the generic parameter `T' of
`Program.<>c__CompilerGenerated0
<T>' (in the previous error)
test.cs(22,25): error CS1662: Cannot convert `lambda expression' to delegate
typ
e `Getter<T,T>' because some of the return types in the block are not
implicitly
 convertible to the delegate return type
test.cs(26,33): error CS0029: Cannot implicitly convert type `T' to `T'
test.cs(26,33): The generic parameter `T' of `Program.CreatePassThru3<T>()'
cann
ot be converted to the generic parameter `T' of
`Program.<>c__CompilerGenerated1
<T>' (in the previous error)
test.cs(26,33): error CS1662: Cannot convert `anonymous method' to delegate
type
 `Getter<T,T>' because some of the return types in the block are not implicitly
convertible to the delegate return type
Compilation failed: 4 error(s), 0 warnings

Expected Results:
Compiled successfully

How often does this happen?
Every time


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