Visual Studio 2012Update1と.NET4.5を使用しています。コードは次のとおりです。
void Test(Action a) { }
void Test(Func<int> a) { }
void TestError()
{
bool throwException = true;
//Resolves to Test(Action a)
Test(() =>
{
});
//Resolves to Test(Action a)
Test(() =>
{
if (throwException) throw new Exception();
});
//Resolves to Test(Func<int> a)
//(This seems like a bug since there is no return value)
Test(() =>
{
throw new Exception();
});
//Resolves to Test(Action a)
//(With warning unreachable code detected)
Test(() =>
{
throw new Exception();
return; //unreachable code detected
});
}
最後の関数呼び出しがActionではなくFuncに誤って解決されているようで、無条件に例外をスローすることに関係しています。
これはバグですか?ありがとう。