C# 4.0 编译器崩溃

发布于 2024-12-12 04:27:39 字数 761 浏览 0 评论 0原文

此代码示例无法编译。有什么解决办法吗?

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 内部编译器错误(地址 5476A4CC 处为 0xc0000005):可能的罪魁祸首是“EMITIL”。编译器中发生内部错误。要解决此问题,请尝试简化或更改下列位置附近的程序。列表顶部的位置更接近发生内部错误的点。可以使用 /errorreport 选项向 Microsoft 报告此类错误。测试应用程序

This code sample is not able to be compiled. Any work arounds out 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 address 5476A4CC): likely culprit is 'EMITIL'. An internal error has occurred in the compiler. To work around this problem, try simplifying or changing the program near the locations listed below. Locations at the top of the list are closer to the point at which the internal error occurred. Errors such as this can be reported to Microsoft by using the /errorreport option. TestApplication

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鱼忆七猫命九 2024-12-19 04:27:39

显然这是一个编译器错误。

我向我们的一位测试人员提到了这一点,他说:

我很高兴地报告,这个问题已经得到修复,您将在 VS 的下一版本中看到此修复。实际上,您也会在 Visual Studio 的 BUILD 开发者预览版中看到它已修复!

对于错误我们深表歉意,并感谢您提请我们注意此问题。

Clearly that is a compiler bug.

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

I’m happy to report that this has already been fixed and you’ll see this fix in the next version of VS. You’ll actually see it fixed in the BUILD Developer Preview for Visual Studio as well!

Apologies for the error, and thanks for bringing this to our attention.

゛时过境迁 2024-12-19 04:27:39

我使用 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 编译器 (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 @ 

这是在linux上测试的。

  1. 您可以在 Windows .NET 上运行使用 mono 创建的二进制文件。
  2. Mono 编译器附带安装程序 MSI,也可以在 Windows 上运行。

I reproduced the crash using VS2010 (WinXP 64).

Two workarounds:

1. don't use the using alias

The following code compiles cleanly 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 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 was tested on linux.

  1. You can run binaries created with mono on Windows .NET.
  2. Mono compiler comes with an installer MSI and runs on Windows as well.
貪欢 2024-12-19 04:27:39

编辑:我现在已经成功地重现了它,并且我有一个潜在的解决方法。

这有效:

csc Test.cs

这不起作用:

csc /debug+ Test.cs

所以看起来这是调试信息的问题。如果您在特定场景中可以没有它,那么您就可以开始...

编辑:我刚刚测试过,这也发生在 /debug:pdbonly 中...

编辑:以防万一有人想知道,我会联系埃里克·利珀特(Eric Lippert)询问此事。

编辑:这是我现在发现的最小重现:

using church = System.Func<dynamic>;

class Program
{
    static void Main() {}
}

EDIT: I've now managed to reproduce it, and I have a potential workaround.

This works:

csc Test.cs

This doesn't:

csc /debug+ Test.cs

So it looks like it's a problem with the debug information. If you can live without that in your particular scenario, you're good to go...

EDIT: I've just tested, and this happens with /debug:pdbonly as well...

EDIT: Just in case anyone was wondering, I'll ping Eric Lippert about this.

EDIT: This is now the minimal repro I've found:

using church = System.Func<dynamic>;

class Program
{
    static void Main() {}
}
十雾 2024-12-19 04:27:39

这是另一个解决方法:不要使用 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);
    }
}

这还有一个好处,即 Church 可以在任何地方定义,而不仅仅是使用别名作为每个文件。

Here's another workaround: don't use Func, use a 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);
    }
}

This also has the benefit, that Church is defined everywhere, and not just as a per-file using alias.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文