Bugzilla – Bug 321462
[GMCS] Generic anon. delegates - runtime error.
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by jokri03@samnet.sdu.dk 2006-06-30 15:34:40 MST ---- I get a runtime error when trying to bind parameteres to methods using generic anonymous delegates. Consider the following code: -------------------------------------------- using System; namespace test { public class Test { public Test() { Binders.Bound<bool> del; del = Binders.Bind<bool,String>(Print, "Hello World"); del(); } public bool Print(String input) { Console.WriteLine(input); return true; } public static void Main() { new Test(); } } public class Binders { public delegate T Bound<T>(); public delegate T Unary<T,A>(A a); public static Bound<T> Bind<T,A>(Unary<T,A> Func, A a) { return delegate () { return Func<T>(a); }; } } } -------------------------------------------- Insted of outputting "Hello World", it produces the following error: -------------------------------------------- ** ERROR **: file object.c: line 559 (compute_class_bitmap): should not be reached aborting... ================================================================= Got a SIGABRT while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application. ================================================================= Stacktrace: at test.Test..ctor () <0xffffffff> at test.Test..ctor () <0x00045> at test.Test.Main () <0x00016> at (wrapper runtime-invoke) System.Object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff> Native stacktrace: mono(mono_handle_native_sigsegv+0xc7) [0x815d807] [0xffffe440] /lib/libc.so.6(abort+0xeb) [0xb7da28fb] /usr/lib/libglib-2.0.so.0(g_logv+0x485) [0xb7f18365] /usr/lib/libglib-2.0.so.0(g_log+0x29) [0xb7f18399] /usr/lib/libglib-2.0.so.0(g_assert_warning+0x72) [0xb7f18412] mono [0x80d6dfd] mono [0x80d6fc7] mono(mono_class_vtable+0xce) [0x80d7cbe] mono [0x812de9e] mono [0x81413cf] mono [0x8146e3b] mono [0x81487df] mono(mono_magic_trampoline+0x1a) [0x807d2ca] [0xb7d68032] [0xb75f9aff] [0xb75f9a6e] mono(mono_runtime_exec_main+0x60) [0x80d92a0] mono(mono_runtime_run_main+0x171) [0x80dc9c1] mono(mono_main+0x102a) [0x805d3ca] /lib/libc.so.6(__libc_start_main+0xd0) [0xb7d8de00] mono [0x805be21] Aborted -------------------------------------------- If I rewrite the code to not use generics as shown below everything works as expected. -------------------------------------------- using System; namespace test { public class Test { public Test() { Binders.Bound del; del = Binders.Bind(Print, "Hello World"); del(); } public bool Print(String input) { Console.WriteLine(input); return true; } public static void Main() { new Test(); } } public class Binders { public delegate bool Bound(); public delegate bool Unary(String a); public static Bound Bind(Unary Func, String a) { return delegate () { return Func(a); }; } } } -------------------------------------------- The sample code is compiled using gmcs, mono version 1.1.15.20060630, since both 1.1.15 and 1.1.13.8 aren't able to compile the code. ---- Additional Comments From martin@ximian.com 2006-07-21 05:31:31 MST ---- Error test; must report CS0307. ---- Additional Comments From martin@ximian.com 2006-07-21 10:37:24 MST ---- There remains a miscompilation after fixing the syntax error. ---- Additional Comments From martin@ximian.com 2006-07-21 10:45:26 MST ---- Simpler test case: ===== using System; public class Binders { public delegate void Test (); public static void Hello<U> (U u) { } public static Test Bind<T> (T t) { return delegate () { Hello (t); }; } static void Main () { } } ===== ---- Additional Comments From miguel@ximian.com 2006-10-07 11:59:43 MST ---- The first sample does nto compile; The second does, and runs well. I have updated it, and this also runs: using System; public class Binders { public delegate void Test (); public static void Hello<U> (U u) { Console.WriteLine (u);} public static Test Bind<T> (T t) { return delegate () { Hello (t); }; } static void Main () { Test t = Bind<int> (5); t ();} } ---- Additional Comments From miguel@ximian.com 2006-10-07 11:59:55 MST ---- flagging as fixed. Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>CRUX Linux 2.2</cf_op_sys_details> Unknown operating system other. Setting to default OS "Other".