提交 8e613486 编写于 作者: K Kevin Halverson

Merge pull request #2273 from daveaglick/master

Fix for #2272 - use of default enum method parameter throws exception
......@@ -11436,6 +11436,30 @@ .maxstack 2
}");
}
[Fact]
public void Bug2272()
{
string source = @"
using System;
public class Parent
{
public int Foo(ConsoleKey e = ConsoleKey.A) { return e == ConsoleKey.A ? 0 : 1; }
}
public class Test
{
public static int Main()
{
var ret = new Parent().Foo();
Console.WriteLine(ret);
return ret;
}
}
";
CompileAndVerify(source, expectedOutput: @"0");
}
[WorkItem(543089, "DevDiv")]
[Fact()]
public void NoOutAttributeOnMethodReturn()
......
......@@ -2037,7 +2037,9 @@ private void DefineParameter(MethodBuilder methodBuilder, ConstructorBuilder con
if (paramType.IsEnum)
{
paramType = paramType.UnderlyingSystemType;
// If emitting the enum, it isn't "created" as this stage so Enum.GetUnderlyingType() will throw
// Otherwise, if the enum is already defined, we should use Enum.GetUnderlyingType() to get the correct type
paramType = paramType is TypeBuilder ? paramType.UnderlyingSystemType : Enum.GetUnderlyingType(paramType);
}
rawValue = Convert.ChangeType(rawValue, paramType, System.Globalization.CultureInfo.InvariantCulture);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册