Bug 318031 (MONO74995) - [GMCS] does not infer types when a parameter is a delegate
Summary: [GMCS] does not infer types when a parameter is a delegate
Status: RESOLVED INVALID
Alias: MONO74995
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-19 19:41 UTC by Daniel Silva
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:17:58 UTC


---- Reported by dsilva@ccs.neu.edu 2005-05-19 12:41:26 MST ----

Description of Problem:

gmcs does not compile this program:


public class Progn {
  public static void Main() {
    string[] names = FP.mapArray(new int[]{1, 2, 3},
                                 delegate (int x) {
                                   return x.ToString(); });
  }
}

class FP {
  public delegate U Mapping<T, U>(T obj);

  public static U[] mapArray<T, U>(T[] array, Mapping<T, U> proc) {
    U[] result = new U[array.Length];
    for (int i = 0; i < array.Length; i++)
      result[i] = proc(array[i]);
    return result;
  }
}

$ gmcs map.cs
map.cs(6) error CS0411: The type arguments for method `mapArray' cannot be
infered from the usage. Try specifying the type arguments explicitly.
Compilation failed: 1 error(s), 0 warnings



---- Additional Comments From martin@ximian.com 2005-06-20 08:42:00 MST ----

Tested and confirmed as NOTABUG.



---- Additional Comments From martin@ximian.com 2005-06-20 08:42:35 MST ----

Stupid Bugzilla - close as NOTABUG, not FIXED.



---- Additional Comments From dsilva@ccs.neu.edu 2005-06-20 13:13:48 MST ----

I don't understand -- why is it not possible for the inferrer see that
the first argument's type is int[] and the second's is (int ->
string), then fill in T and U for mapArray?



---- Additional Comments From martin@ximian.com 2005-06-20 16:43:00 MST ----

Not entirely sure (csc doesn't compile this code either), but my guess
is that the reason is that the anonymous delegate's signature only
contains T, but not U.  U is only used in the delegate's return type,
but that's not part of the signature.





---- Additional Comments From dsilva@ccs.neu.edu 2005-06-20 22:35:02 MST ----

I see.  Thanks.


Unknown operating system unknown. Setting to default OS "Other".