Skip to content
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

Partial (simplest possible case) fix for OnError GoTo #999

Merged
merged 8 commits into from
May 4, 2023

Conversation

GrahamTheCoder
Copy link
Member

@GrahamTheCoder GrahamTheCoder commented Mar 26, 2023

Partial (simplest possible case) fix for #426

Simplest case covered here: A single top level On Error Go To, everything after it could be placed in a try catch and go to the outer label

May be possible to cover in future

  • OnErrorGoTo statement and label in same scope, but not top-level (e.g. nested in an if statment/loop)

  • Extend that system to two statements within a scope (e.g. changing the error handler part way through, it would be possible to have a nested try catch block for the second one, and use an filter clause to avoid hitting the outer one

Still no sensible known solution

General solution: The difficulty is that in C# the labels are scoped to the containing block, so it isn't possible to goto a label straight from a catch block. I've therefore created a loop and switch to allow it to re-enter the scope where it's possible to go to the label. That still won't work for labels inside if blocks and I'm still trying to think of a less verbose/ugly way of handling this in general.

Future

The solution may be to make a best effort at converting to working code, but to always spit out a code comment containing the original VB.
It'd also be possible in a comment to add a suggested starting point for a maintainable solution i.e. Just put it in a simple try catch block.

@GrahamTheCoder GrahamTheCoder changed the title Onerror OnError GoTo Mar 27, 2023
catch
{
}
while (catchIndex != -1);
Copy link
Member Author

@GrahamTheCoder GrahamTheCoder May 3, 2023

Choose a reason for hiding this comment

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

This is the example output - which is what's discouraging me from further work on this...
One other possible avenue might be to use something like DynamicMethod with IL.Emit to get around the restrictions of scopes and jump to labels with less boilerplate.

TODO:
* Deal with non-returning code paths
* Ensure loops within the method can still break/continue as expected
@GrahamTheCoder GrahamTheCoder marked this pull request as ready for review May 3, 2023 23:53
@GrahamTheCoder GrahamTheCoder merged commit 5a5dd8f into master May 4, 2023
@GrahamTheCoder GrahamTheCoder deleted the onerror branch May 4, 2023 00:28
@GrahamTheCoder GrahamTheCoder changed the title OnError GoTo Partial (simplest possible case) fix for OnError GoTo May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant