C # 4.0 Compiler Crash

This sample code cannot be compiled. Any work around there?

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { using church = Func<dynamic, dynamic, dynamic>; class Program { static void Main(string[] args) { church True = (a, b) => a; church False = (a, b) => b; Func<church, church, church> And = (x, y) => x(y(True, False), False); } } } 

Error 6 Internal compiler error (0xc0000005 at 5476A4CC): the likely culprit is "EMITIL". An internal error occurred in the compiler. To work around this problem, try simplifying or modifying the program near the following locations. The location at the top of the list is closer to the point at which the internal error occurred. Such errors can be reported to Microsoft using the / errorreport option. Testapplication

+50
compiler-construction c # crash
Oct 25 '11 at 19:18
source share
4 answers

I reproduced the crash using VS2010 (WinXP 64).

Two workarounds:

1. do not use using alias

The following code compiles on VS2010:

 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Func<dynamic, dynamic, dynamic> True = (a, b) => a; Func<dynamic, dynamic, dynamic> False = (a, b) => b; Func<Func<dynamic, dynamic, dynamic>, Func<dynamic, dynamic, dynamic>, Func<dynamic, dynamic, dynamic> > And = (x, y) => x(y(True, False), False); } } } 

2. use the Mono compiler

No problem with the Mono 2.10 compiler (dmcs).

 [mono] /tmp @ dmcs test.cs test.cs(18,42): warning CS0219: The variable `And' is assigned but its value is never used Compilation succeeded - 1 warning(s) [mono] /tmp @ ./test.exe [mono] /tmp @ 

This has been tested on Linux.

  • You can run executable files created using mono in Windows.NET.
  • The monocompiler comes with an MSI installer and runs on Windows.
+27
Oct 25 '11 at 19:22
source share

Obviously, this is a compiler error.

I mentioned this to one of our testers, and he says:

I am pleased to announce that this has already been fixed, and you will see this fix in the next version of VS. In fact, you will see that it is fixed in the preliminary presentation of the BUILD developer for Visual Studio!

Sorry for the mistake, and thank you for bringing this to our attention.

+49
Oct 25 2018-11-11T00:
source share

EDIT: I was able to reproduce it, and I have a potential solution.

It works:

 csc Test.cs 

It does not mean:

 csc /debug+ Test.cs 

So this seems like a problem with debugging information. If you can live without it in your specific scenario, you should go ...

EDIT: I just checked and this happens with /debug:pdbonly ...

EDIT: Just in case, someone wondered if I would ping Eric Lippert about it.

EDIT: now this is the minimum registry I found:

 using church = System.Func<dynamic>; class Program { static void Main() {} } 
+21
Oct 25 '11 at 19:30
source share

Here is another way: do not use Func , use the good old delegate type.

 public delegate dynamic Church(dynamic x, dynamic y); class Program { static void Main(string[] args) { Church True = (a, b) => a; Church False = (a, b) => b; Func<Church, Church, Church> And = (x, y) => x(y(True, False), False); } } 

It also has the advantage that the Church is defined everywhere, and not just as a file using an alias.

+14
Oct 25 2018-11-21T00:
source share



All Articles