提交 9c66fe09 编写于 作者: N Neal Gafter

Generalize assert to include source statements that result in bound try

Fixes #2567
上级 ec9f9753
......@@ -137,7 +137,12 @@ internal sealed class AsyncExceptionHandlerRewriter : BoundTreeRewriter
public override BoundNode VisitTryStatement(BoundTryStatement node)
{
var tryStatementSyntax = node.Syntax;
Debug.Assert(tryStatementSyntax.IsKind(SyntaxKind.TryStatement));
// If you add a syntax kind to the assertion below, please also ensure
// that the scenario has been tested with Edit-and-Continue.
Debug.Assert(
tryStatementSyntax.IsKind(SyntaxKind.TryStatement) ||
tryStatementSyntax.IsKind(SyntaxKind.UsingStatement) ||
tryStatementSyntax.IsKind(SyntaxKind.ForEachStatement));
BoundStatement finalizedRegion;
BoundBlock rewrittenFinally;
......
......@@ -3328,5 +3328,40 @@ static void Main(string[] args)
CompileAndVerify(comp.WithOptions(TestOptions.ReleaseExe), expectedOutput: expectedOutput);
}
[Fact, WorkItem(2567, "https://github.com/dotnet/roslyn/issues/2567")]
public void AwaitInUsingAndForeach()
{
var source = @"
using System.Threading.Tasks;
using System;
class Program
{
System.Collections.Generic.IEnumerable<int> ien = null;
async Task<int> Test(IDisposable id, Task<int> task)
{
try
{
foreach (var i in ien)
{
return await task;
}
using (id)
{
return await task;
}
}
catch (Exception)
{
return await task;
}
}
public static void Main() {}
}";
var comp = CreateCompilation(source, options: TestOptions.DebugExe);
CompileAndVerify(comp);
CompileAndVerify(comp.WithOptions(TestOptions.ReleaseExe));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册