提交 8d05c078 编写于 作者: V vsadov

Added VB scenarios.

VB does not have this particular bug and corresponding scenario works correctly.
There are however other bugs beyond the scope of what is fixed in this PR.
上级 eee918a5
......@@ -2325,6 +2325,136 @@ BC31143: Method 'Public Overloads ByRef Function F() As Integer' does not have a
</expected>)
End Sub
<Fact>
<WorkItem(17706, "https://github.com/dotnet/roslyn/issues/17706")>
Public Sub SpillingByrefCall_NoSpilling()
Dim comp1 = CreateCSharpCompilation(
"
using System;
public class TestClass
{
int x = 0;
public ref int Save(int y)
{
x = y;
return ref x;
}
public void Write(ref int y)
{
Console.WriteLine(y);
}
public void Write(ref int y, int z)
{
Console.WriteLine(y);
}
}")
comp1.VerifyDiagnostics()
Dim comp2 = CreateVisualBasicCompilation(
Nothing,
"
Imports System.Threading.Tasks
Module Module1
Sub Main()
TestMethod().Wait()
End Sub
Async Function TestMethod() As Task
Dim inst = New TestClass
' this is OK. `ref` call is not spilled.
' prints: 10 (last value)
inst.Write(inst.Save(Await Task.FromResult(10)))
' this is OK. `ref` call is not spilled.
' prints: 22 (last value)
inst.Write(inst.Save(Await Task.FromResult(20)), inst.Save(22))
End Function
End Module
",
referencedCompilations:={comp1},
referencedAssemblies:=LatestVbReferences,
compilationOptions:=TestOptions.DebugExe)
comp2.AssertTheseDiagnostics()
Dim verifier = CompileAndVerify(comp2, expectedOutput:=
"
10
22
")
verifier.VerifyDiagnostics()
End Sub
<Fact(Skip:="https://github.com/dotnet/roslyn/issues/24275")>
<WorkItem(24275, "https://github.com/dotnet/roslyn/issues/24275")>
Public Sub SpillingByrefCall_Spilling()
Dim comp1 = CreateCSharpCompilation(
"
using System;
public class TestClass
{
int x = 0;
public ref int Save(int y)
{
x = y;
return ref x;
}
public void Write(ref int y)
{
Console.WriteLine(y);
}
public void Write(ref int y, int z)
{
Console.WriteLine(y);
}
}")
comp1.VerifyDiagnostics()
Dim comp2 = CreateVisualBasicCompilation(
Nothing,
"
Imports System.Threading.Tasks
Module Module1
Sub Main()
TestMethod().Wait()
End Sub
Async Function TestMethod() As Task
Dim inst = New TestClass
' ERROR?
' currently `ref` is spilled 'by-value' and assert fires.
inst.Write(inst.Save(Await Task.FromResult(30)), inst.Save(Await Task.FromResult(33)))
End Function
End Module
",
referencedCompilations:={comp1},
referencedAssemblies:=LatestVbReferences,
compilationOptions:=TestOptions.DebugExe)
comp2.AssertTheseDiagnostics()
Dim verifier = CompileAndVerify(comp2, expectedOutput:=
"
??
")
verifier.VerifyDiagnostics()
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册