【发布时间】:2010-12-20 23:51:46
【问题描述】:
我遇到了移植到单声道 2.8.1 的一些无法预料的后果。问题可以归结为一个示例程序(在将几个类和大约 1000 行代码剪切到下面引用的文件之后,我无法进一步减少它)
public class Person
{
public Person(int age, string name = null){}
public Person(double income, string name = null){}
public Person(double income, int age, string name = null){}
}
class Program
{
static void Main()
{
Person p = new Person(1.0, name: "John Doe");
}
}
用 mcs 编译上述代码给出输出:
test.cs(22,24): error CS0584: Internal compiler error: Internal error
test.cs(22,20): error CS0266: Cannot implicitly convert type `object' to `NamedParams.Person'.
An explicit conversion exists (are you missing a cast?)
Compilation failed: 2 error(s), 0 warnings
删除使用可选/命名参数(即调用 new Person(1.0, null, "John Doe")或 new Person(1.0, null, name:"John Doe") 或 new Person(1.0, "John Doe" ") ) 导致完美的编译。此外,在 VS2010 下,文件(以及我开始使用的整个解决方案)编译得很好。强制转换会删除错误 CS0266,但不会删除 CS0584 - 所以这并不奇怪。
我的问题:是我做错了什么,还是 mcs(即 mcs 中的错误对我来说很明显——还有什么 ,,internal error'' 是什么意思,但也许这样的程序不会编译没关系),或者也许VS2010中的微软编译器不应该让这样的代码编译?
我敢打赌是 mcs 错了(无法猜出正确的构造函数),但也许不是这样,我不应该知道得更好?
PS。我尝试在 Google 和 Novell 的 Bugzilla 中搜索类似的已知错误,但找不到任何相关内容。再说一次,我可能是盲人;)
【问题讨论】:
-
你能设置一个字符串为空吗...
-
使用 Visual Studio 编译这个没有错误。不过,我没有单声道来尝试确认。
-
@Courtney:Mono 可在线使用here。
-
mono 2.6.7 在 Mono.CSharp.MethodGroupExpr.IsApplicable 中也崩溃
-
在我看来确实像一个 Mono 错误。注意 Mono 也可以使用命名参数,但您必须删除最后一个重载(
Person(double income, int age, string name = null)重载)。显然,当调用中使用和命名参数时,Mono 对涉及可选参数的重载决议感到困惑。什么的。