c# 4.0编译器崩溃
本文关键字:崩溃 编译器 | 更新日期: 2023-09-27 18:12:28
无法编译此代码示例。还有别的办法吗?
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);
}
}
}
错误6内部编译错误 (0xc0000005 at address 5476A4CC):可能的罪魁祸首是'EMITIL'。编译器发生内部错误。要解决这个问题,请尝试在下面列出的位置附近简化或更改程序。列表顶部的位置更接近内部错误发生的位置。这样的错误可以通过使用/errorreport选项报告给微软。TestApplication
显然这是一个编译器错误。
我向我们的一个测试人员提到了这一点,他说:
我很高兴地告诉大家,这个问题已经被修复了,你会在下一个版本的vs中看到这个问题的修复,你也会在Visual Studio的BUILD开发者预览中看到它的修复!
为错误道歉,并感谢您提醒我们。
我使用VS2010 (WinXP 64)再现了崩溃。
两个解决方法:
1。不要使用using
别名
下面的代码可以在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。使用Mono编译器
Mono 2.10编译器(dmc)没有问题。
[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 @
在linux上进行了测试。
- 你可以在Windows . net上运行mono创建的二进制文件。
- Mono编译器带有安装程序MSI,也可以在Windows上运行。
编辑:我现在已经成功地复制了它,和我有一个潜在的解决方案。
如此:
csc Test.cs
这并不:
csc /debug+ Test.cs
所以看起来这是调试信息的问题。如果你可以在特定的场景中没有它,你就可以去了。
编辑:我刚刚测试过,这也发生在/debug:pdbonly
上…
编辑:这是现在我找到的最小的复制:
using church = System.Func<dynamic>;
class Program
{
static void Main() {}
}
这是另一个解决方法:不要使用Func
,使用一个好的旧委托类型。
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);
}
}
这也有一个好处,教会是无处不在的定义,而不仅仅是作为每个文件使用别名。