提交 b7a83930 编写于 作者: V vsadov

Ensure that IDisposable temps in a case of dynamic using have "Using" kind.

These temps have special longlived kind "Using", but were produced as regular temps in the case involving dynamic.

Fixes #5323
上级 d741ac75
......@@ -121,7 +121,7 @@ private BoundBlock RewriteExpressionUsingStatement(BoundUsingStatement node, Bou
@checked: false,
constantValueOpt: rewrittenExpression.ConstantValue);
boundTemp = _factory.StoreToTemp(tempInit, out tempAssignment);
boundTemp = _factory.StoreToTemp(tempInit, out tempAssignment, kind: SynthesizedLocalKind.Using);
}
else
{
......@@ -183,7 +183,7 @@ private BoundBlock RewriteDeclarationUsingStatement(CSharpSyntaxNode usingSyntax
@checked: false);
BoundAssignmentOperator tempAssignment;
BoundLocal boundTemp = _factory.StoreToTemp(tempInit, out tempAssignment);
BoundLocal boundTemp = _factory.StoreToTemp(tempInit, out tempAssignment, kind: SynthesizedLocalKind.Using);
BoundStatement tryFinally = RewriteUsingStatementTryFinally(usingSyntax, tryBlock, boundTemp);
......
......@@ -14614,6 +14614,96 @@ .maxstack 10
}");
}
[WorkItem(5323, "https://github.com/dotnet/roslyn/issues/5323")]
[Fact]
public void DynamicUsingWithYield1()
{
var source =
@"
using System.Collections.Generic;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
foreach(var i in Iter())
{
System.Console.WriteLine(i);
}
}
static IEnumerable<Task> Iter()
{
dynamic d = 123;
using (var t = D(d))
{
yield return t;
t.Wait();
}
}
static Task D(dynamic arg)
{
return Task.FromResult(1);
}
}";
var comp = CreateCompilationWithMscorlib45(source, references: new[] { SystemCoreRef, CSharpRef }, options: TestOptions.ReleaseExe);
CompileAndVerify(comp, expectedOutput: @"System.Threading.Tasks.Task`1[System.Int32]");
comp = CreateCompilationWithMscorlib45(source, references: new[] { SystemCoreRef, CSharpRef }, options: TestOptions.DebugExe);
CompileAndVerify(comp, expectedOutput: @"System.Threading.Tasks.Task`1[System.Int32]");
}
[WorkItem(5323, "https://github.com/dotnet/roslyn/issues/5323")]
[Fact]
public void DynamicUsingWithYield2()
{
var source =
@"
using System.Collections.Generic;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
foreach(var i in Iter())
{
System.Console.WriteLine(i);
}
}
static IEnumerable<Task> Iter()
{
dynamic d = 123;
var t = D(d);
using (t)
{
yield return t;
t.Wait();
}
}
static Task D(dynamic arg)
{
return Task.FromResult(1);
}
}";
var comp = CreateCompilationWithMscorlib45(source, references: new[] { SystemCoreRef, CSharpRef }, options: TestOptions.ReleaseExe);
CompileAndVerify(comp, expectedOutput: @"System.Threading.Tasks.Task`1[System.Int32]");
comp = CreateCompilationWithMscorlib45(source, references: new[] { SystemCoreRef, CSharpRef }, options: TestOptions.DebugExe);
CompileAndVerify(comp, expectedOutput: @"System.Threading.Tasks.Task`1[System.Int32]");
}
#endregion
#region Using
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册