Bugzilla – Bug 318031
[GMCS] does not infer types when a parameter is a delegate
Last modified: 2007-09-15 21:24:23 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".