提交 9d07d512 编写于 作者: T Ty Overby 提交者: GitHub

fill out the visitor for BoundMethodGroup (#13832)

* fill out the visitor for BoundMethodGroup

* add vb tests and yield in c# test
上级 1b544075
......@@ -854,6 +854,13 @@ public override BoundNode VisitConversion(BoundConversion node)
type: node.Type));
}
public override BoundNode VisitMethodGroup(BoundMethodGroup node)
{
BoundSpillSequenceBuilder builder = null;
var receiver = VisitExpression(ref builder, node.ReceiverOpt);
return UpdateExpression(builder, node.Update(node.TypeArgumentsOpt, node.Name, node.Methods, node.LookupSymbolOpt, node.LookupError, node.Flags, receiver, node.ResultKind));
}
public override BoundNode VisitDelegateCreationExpression(BoundDelegateCreationExpression node)
{
BoundSpillSequenceBuilder builder = null;
......
......@@ -2934,5 +2934,76 @@ public static void Main()
";
CompileAndVerify(source, expected);
}
[Fact]
[WorkItem(13734, "https://github.com/dotnet/roslyn/issues/13734")]
public void MethodGroupConversionNoSpill()
{
string source = @"
using System.Threading.Tasks;
using System;
public class AsyncBug {
public static void Main()
{
Boom().GetAwaiter().GetResult();
}
public static async Task Boom()
{
Func<Type> f = (await Task.FromResult(1)).GetType;
Console.WriteLine(f());
}
}
";
var v = CompileAndVerify(source, "System.Int32");
}
[Fact]
[WorkItem(13734, "https://github.com/dotnet/roslyn/issues/13734")]
public void MethodGroupConversionWithSpill()
{
string source = @"
using System.Threading.Tasks;
using System;
using System.Linq;
using System.Collections.Generic;
namespace AsyncBug
{
class Program
{
private class SomeClass
{
public bool Method(int value)
{
return value % 2 == 0;
}
}
private async Task<SomeClass> Danger()
{
await Task.Yield();
return new SomeClass();
}
private async Task<IEnumerable<bool>> Killer()
{
return (new int[] {1, 2, 3, 4, 5}).Select((await Danger()).Method);
}
static void Main(string[] args)
{
foreach (var b in new Program().Killer().GetAwaiter().GetResult()) {
Console.WriteLine(b);
}
}
}
}
";
var expected = new bool[] { false, true, false, true, false }.Aggregate("", (str, next) => str += $"{next}{Environment.NewLine}");
var v = CompileAndVerify(source, expected);
}
}
}
......@@ -9074,6 +9074,79 @@ BC30456: 'AwaitOnCompleted' is not a member of 'AsyncVoidMethodBuilder'.
</expected>)
End Sub
<Fact, WorkItem(13734, "https://github.com/dotnet/roslyn/issues/13734")>
Public Sub MethodGroupWithConversionNoSpill()
Dim source = <compilation name="Async">
<file name="a.vb">
Imports System
Imports System.Threading.Tasks
Public Class AsyncBug
Public Shared Sub Main()
AsyncBug.Boom().GetAwaiter().GetResult()
End Sub
Public Async Shared Function Boom() As Task
Dim func As Func(Of Type) = Addressof (Await Task.FromResult(1)).GetType
Console.WriteLine(func())
End Function
End Class
</file>
</compilation>
Dim expectedOutput = <![CDATA[System.Int32]]>
Dim compilation = CompilationUtils.CreateCompilationWithReferences(source, references:=LatestVbReferences, options:=TestOptions.DebugExe)
CompileAndVerify(compilation, expectedOutput:=expectedOutput)
CompileAndVerify(compilation.WithOptions(TestOptions.ReleaseExe), expectedOutput:=expectedOutput)
End Sub
<Fact, WorkItem(13734, "https://github.com/dotnet/roslyn/issues/13734")>
Public Sub MethodGroupConversionWithSpill()
Dim source = <compilation name="Async">
<file name="a.vb">
imports System.Threading.Tasks
imports System
imports System.Linq
imports System.Collections.Generic
class Program
class SomeClass
Public Function Method(value as Integer) as Boolean
Return value Mod 2 = 0
End Function
End Class
private Async Function Danger() as Task(Of SomeClass)
await Task.Yield()
return new SomeClass()
End Function
Async function Killer() as Task(Of IEnumerable(Of Boolean))
Return {1, 2, 3, 4, 5}.Select(AddressOf (Await Danger()).Method)
End Function
Shared Sub Main(args As String())
For Each b in new Program().Killer().GetAwaiter().GetResult()
Console.WriteLine(b)
Next
End Sub
End Class
</file>
</compilation>
Dim expectedOutput = <![CDATA[False
True
False
True
False
]]>
Dim compilation = CompilationUtils.CreateCompilationWithReferences(source, references:=LatestVbReferences, options:=TestOptions.DebugExe)
CompileAndVerify(compilation, expectedOutput:=expectedOutput)
CompileAndVerify(compilation.WithOptions(TestOptions.ReleaseExe), expectedOutput:=expectedOutput)
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册