提交 e87ce86f 编写于 作者: V VSadov

Fixed incorrect codegen when rethrow is used in a regular catch next to catches with awaits.

Catches without awaits should not be rewritten in a context of an await catch frame since rethrow in such catch is just a regular rethrow.
Fixes #1334
上级 531ddce1
......@@ -501,7 +501,12 @@ public override BoundNode VisitCatchBlock(BoundCatchBlock node)
{
if (!_analysis.CatchContainsAwait(node))
{
return base.VisitCatchBlock(node);
var origCurrentAwaitCatchFrame = _currentAwaitCatchFrame;
_currentAwaitCatchFrame = null;
var result = base.VisitCatchBlock(node);
_currentAwaitCatchFrame = origCurrentAwaitCatchFrame;
return result;
}
var currentAwaitCatchFrame = _currentAwaitCatchFrame;
......
......@@ -1229,6 +1229,75 @@ public static void Main()
CompileAndVerify(source, expectedOutput: expected);
}
[WorkItem(74, "https://github.com/dotnet/roslyn/issues/1334")]
[Fact]
public void AsyncInCatchRethrow01()
{
var source = @"
using System;
using System.Threading.Tasks;
class Test
{
static async Task<int> F()
{
await Task.Yield();
return 2;
}
static async Task<int> G()
{
int x = 0;
try
{
try
{
x = x / x;
}
catch (ArgumentNullException)
{
x = await F();
}
catch
{
throw;
}
}
catch(DivideByZeroException ex)
{
x = await F();
System.Console.WriteLine(ex.Message);
}
return x;
}
public static void Main()
{
System.Globalization.CultureInfo saveUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;
try
{
Task<int> t2 = G();
t2.Wait(1000 * 60);
Console.WriteLine(t2.Result);
}
finally
{
System.Threading.Thread.CurrentThread.CurrentUICulture = saveUICulture;
}
}
}";
var expected = @"
Attempted to divide by zero.
2
";
CompileAndVerify(source, expectedOutput: expected);
}
[Fact]
public void AsyncInCatchFilter()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册