提交 179ac4ce 编写于 作者: N Neal Gafter

Merge pull request #2733 from gafter/fix2567

Generalize assert to include source statements that result in bound try
...@@ -137,7 +137,12 @@ internal sealed class AsyncExceptionHandlerRewriter : BoundTreeRewriter ...@@ -137,7 +137,12 @@ internal sealed class AsyncExceptionHandlerRewriter : BoundTreeRewriter
public override BoundNode VisitTryStatement(BoundTryStatement node) public override BoundNode VisitTryStatement(BoundTryStatement node)
{ {
var tryStatementSyntax = node.Syntax; 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; BoundStatement finalizedRegion;
BoundBlock rewrittenFinally; BoundBlock rewrittenFinally;
......
...@@ -3328,5 +3328,40 @@ static void Main(string[] args) ...@@ -3328,5 +3328,40 @@ static void Main(string[] args)
CompileAndVerify(comp.WithOptions(TestOptions.ReleaseExe), expectedOutput: expectedOutput); 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.
先完成此消息的编辑!
想要评论请 注册