我遇到了一些無法預料的移植到mono 2.8.1的後果。問題可以被歸結爲一個示例程序(I一直無法進一步降低它,切割幾個類和〜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
取出使用可選/命名參數(即調用新的Person(1.0,空, 「李四」)或新的Person(1.0,空,名稱: 「李四」),或新的Person( 1.0,「John Doe」))導致了完美的編譯。此外,在VS2010下,文件(以及我開始的整個解決方案)編譯得很好。 Casting會移除錯誤CS0266,但不會移除CS0584 - 因此在那裏不會感到意外。我的問題:是我做錯了什麼,或者mcs(即mcs中的bug對我來說很明顯 - 還有什麼,內部錯誤會是什麼意思,但也許沒關係,這樣的程序不會編譯),或者也許在VS2010中的微軟編譯器不應該讓這樣的代碼編譯?
我敢打賭,這是MCS誰的錯(不能猜對構造函數),但也許它,否則,我不應該知道的?
PS。我嘗試在Google和Novell的Bugzilla中搜索這樣一個已知的bug,但無法找到任何相關的東西。再一次,我可能會失明;)
你甚至可以設置一個字符串爲空... – Blam 2010-12-20 23:55:23
有沒有錯誤編譯使用visual studio。我沒有單聲道來嘗試它,以確認。 – 2010-12-21 00:05:54
@Courtney:單聲道可在線獲取[此處](http://ideone.com/kZ2Eo)。 – Vlad 2010-12-21 00:07:11