-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Recognize a VB exception filter's type test #4134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
siegfriedpammer
merged 3 commits into
icsharpcode:master
from
dualfroz:fix-vb-exception-filter-type-test
Sep 15, 2026
+4,475
−9
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
ICSharpCode.Decompiler.Tests/TestCases/Correctness/VBOnErrorCorrectness.vb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
91
ICSharpCode.Decompiler.Tests/TestCases/VBPretty/Issue3659.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
17
ICSharpCode.Decompiler.Tests/TestCases/VBPretty/Issue3659.vb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| On Error GoTo Handler | ||
| Func(Me, value) | ||
| Exit Sub | ||
| Handler: | ||
| ShowMessage("VBFunction", 0, "Exception", Nothing, 0) | ||
| End Sub | ||
| End Class | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 GoTowhich we don't really have plans on supporting.