Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ICSharpCode.Decompiler.Tests/CorrectnessTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ public async Task Uninit([ValueSource(nameof(noMonoOptions))] CompilerOptions op
await RunVB(options: options);
}

[Test]
public async Task VBOnErrorCorrectness([ValueSource(nameof(noMonoOptions))] CompilerOptions options)
{
await RunVB(options: options);
}

[Test]
public async Task MemberLookup([ValueSource(nameof(defaultOptions))] CompilerOptions options)
{
Expand Down Expand Up @@ -497,6 +503,18 @@ async Task RunVB([CallerMemberName] string testName = null, CompilerOptions opti
outputFile = await Tester.CompileVB(Path.Combine(TestCasePath, testFileName), options,
outputFileName: testOutputFileName).ConfigureAwait(false);
string decompiledCodeFile = await Tester.DecompileCSharp(outputFile.PathToAssembly, Tester.GetSettings(options)).ConfigureAwait(false);
if ((options & CompilerOptions.UseRoslynMask) == 0)
{
// For second pass, use roslyn instead of the legacy csc.
// VB error handling compiles to exception filters, which C# 5 cannot express.
options |= CompilerOptions.UseRoslynLatest | CompilerOptions.TargetNet40;
}
else if ((options & CompilerOptions.UseRoslyn2_10_0) != 0 && (options & CompilerOptions.TargetNet40) == 0)
{
// The .NET Core 2.2 Microsoft.VisualBasic.dll lacks most of the VB runtime
// that decompiled VB code calls, such as Information.Err.
options = (options & ~CompilerOptions.UseRoslyn2_10_0) | CompilerOptions.UseRoslynLatest;
}
decompiledOutputFile = await Tester.CompileCSharp(decompiledCodeFile, options).ConfigureAwait(false);

await Tester.RunAndCompareOutput(testFileName, outputFile.PathToAssembly, decompiledOutputFile.PathToAssembly, decompiledCodeFile, (options & CompilerOptions.UseTestRunner) != 0, (options & CompilerOptions.Force32Bit) != 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<None Include="TestCases\Correctness\StackTests.il" />
<None Include="TestCases\Correctness\StackTypes.il" />
<None Include="TestCases\Correctness\Uninit.vb" />
<None Include="TestCases\Correctness\VBOnErrorCorrectness.vb" />
<None Include="TestCases\Disassembler\Pretty\GenericConstraints.il" />
<None Include="TestCases\Disassembler\Pretty\NegativeConstants.il" />
<None Include="TestCases\Disassembler\Pretty\InterfaceImplAttributes.il" />
Expand Down Expand Up @@ -161,6 +162,8 @@
<None Include="TestCases\VBPretty\VBAutomaticEvents.vb" />
<None Include="TestCases\VBPretty\VBNonGenericForEach.vb" />
<None Include="TestCases\VBPretty\YieldReturn.vb" />
<None Include="TestCases\VBPretty\VBTryCatchFinally.vb" />
<None Include="TestCases\VBPretty\VBOnError.vb" />
<None Include="TestCases\VBPretty\Issue1906.vb" />
<None Include="TestCases\VBPretty\Issue2192.vb" />
<None Include="TestCases\VBPretty\Select.vb" />
Expand Down Expand Up @@ -224,6 +227,8 @@
<Compile Remove="TestCases\ILPretty\Issue3729.cs" />
<None Include="TestCases\ILPretty\Issue3729.cs" />
<None Include="TestCases\ILPretty\Issue3729.il" />
<Compile Remove="TestCases\VBPretty\Issue3659.cs" />
<None Include="TestCases\VBPretty\Issue3659.cs" />
<Compile Remove="TestCases\ILPretty\SpanConversionOperatorMismatch.cs" />
<None Include="TestCases\ILPretty\SpanConversionOperatorMismatch.cs" />
<Compile Remove="TestCases\ILPretty\FSharpLoops_Debug.cs" />
Expand Down Expand Up @@ -304,6 +309,8 @@
<None Include="TestCases\Ugly\TopLevelProgramAsync.Expected.cs" />
<Compile Remove="TestCases\VBPretty\VBCompoundAssign.cs" />
<None Include="TestCases\VBPretty\VBCompoundAssign.cs" />
<Compile Remove="TestCases\VBPretty\VBOnError.cs" />
<None Include="TestCases\VBPretty\VBOnError.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Imports System
Imports Microsoft.VisualBasic

Module VBOnErrorCorrectness
Sub Main()
ResumeNext()
GoToHandler()
GoToHandlerResumeNext()
Console.WriteLine(GoToHandlerResume(3))
GoToHandlerResumeLabel()
Try
GoToZero()
Catch ex As InvalidOperationException
Console.WriteLine("outer: " & ex.Message)
End Try
Console.WriteLine(GoToHandlerWithResult())
End Sub

Sub FailWhilePositive(retries As Integer)
If retries > 0 Then Fail("retry " & retries)
End Sub

Sub Fail(message As String)
Throw New InvalidOperationException(message)
End Sub

Sub ResumeNext()
On Error Resume Next
Fail("a")
Console.WriteLine("after a: " & Err.Number & " " & Err.Description)
Err.Clear()
Console.WriteLine("cleared: " & Err.Number)
End Sub

Sub GoToHandler()
On Error GoTo Handler
Fail("b")
Console.WriteLine("unreachable")
Exit Sub
Handler:
Console.WriteLine("handler: " & Err.Description)
End Sub

Sub GoToHandlerResumeNext()
On Error GoTo Handler
Fail("c1")
Console.WriteLine("between")
Fail("c2")
Console.WriteLine("done")
Exit Sub
Handler:
Console.WriteLine("handler: " & Err.Description)
Resume Next
End Sub

Function GoToHandlerResume(retries As Integer) As Integer
On Error GoTo Handler
FailWhilePositive(retries)
Return retries
Handler:
retries -= 1
Resume
End Function

Sub GoToHandlerResumeLabel()
On Error GoTo Handler
Fail("d")
Done:
Console.WriteLine("done")
Exit Sub
Handler:
Console.WriteLine("handler: " & Err.Description)
Resume Done
End Sub

Sub GoToZero()
On Error Resume Next
Fail("e1")
Console.WriteLine("swallowed")
On Error GoTo 0
Fail("e2")
Console.WriteLine("unreachable")
End Sub

Function GoToHandlerWithResult() As Integer
On Error GoTo Handler
Return Integer.Parse("x")
Handler:
Return -1
End Function
End Module
91 changes: 91 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/VBPretty/Issue3659.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Runtime.CompilerServices;
using Microsoft.VisualBasic.CompilerServices;

public class Issue3659
{
public static void Func(ref Issue3659 obj, object value)
{
}

public static int ShowMessage(string a, int b, string c, object d, int e)
{
return 0;
}

internal void VBFunction(object value)
{
#if OPT || LEGACY_VBC
int try0000_dispatch = -1;
#else
int try0001_dispatch = -1;
#endif
int num2 = default;
int num = default;
while (true)
{
try
{
/*Note: ILSpy has introduced the following switch to emulate a goto from catch-block to try-block*/;
#if OPT || LEGACY_VBC
switch (try0000_dispatch)
#else
switch (try0001_dispatch)
#endif
{
default:
{
ProjectData.ClearProjectError();
num2 = 2;
Issue3659 obj = this;
Func(ref obj, RuntimeHelpers.GetObjectValue(value));
#if OPT || LEGACY_VBC
goto end_IL_0000;
#else
goto end_IL_0001;
#endif
}
#if OPT || LEGACY_VBC
case 45:
#else
case 50:
#endif
num = -1;
switch (num2)
{
case 2:
ShowMessage("VBFunction", 0, "Exception", null, 0);
#if OPT || LEGACY_VBC
goto end_IL_0000;
#else
goto end_IL_0001;
#endif
}
break;
}
}
catch (Exception ex) when ((num2 != 0) & (num == 0))
{
ProjectData.SetProjectError(ex);
#if OPT || LEGACY_VBC
try0000_dispatch = 45;
#else
try0001_dispatch = 50;
#endif
continue;
}
throw ProjectData.CreateProjectError(-2146828237);
continue;
#if OPT || LEGACY_VBC
end_IL_0000:
#else
end_IL_0001:
#endif
break;
}
if (num != 0)
{
ProjectData.ClearProjectError();
}
}
}
17 changes: 17 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/VBPretty/Issue3659.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Imports System
Public Class Issue3659
Public Shared Sub Func(ByRef obj As Issue3659, value As Object)
End Sub

Public Shared Function ShowMessage(a As String, b As Integer, c As String, d As Object, e As Integer) As Integer
Return 0
End Function

Friend Sub VBFunction(value As Object)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be a rather special case, namely On Error GoTo which we don't really have plans on supporting.

On Error GoTo Handler
Func(Me, value)
Exit Sub
Handler:
ShowMessage("VBFunction", 0, "Exception", Nothing, 0)
End Sub
End Class
Loading
Loading