Repository navigation
Convert On Error / Resume statements - #1324
Merged
GrahamTheCoder merged 48 commits intoNov 18, 2026
Merged
GrahamTheCoder merged 48 commits into
GrahamTheCoder merged 48 commits into
Conversation
Design only, no behaviour change. Covers the VB lowering rules, the C# constraints, per-statement guard output shapes, and the decisions on Err usage, loop headers and secondary errors. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Pure refactor, no output change. The existing single try/catch conversion now lives in CSharp/OnError behind OnErrorMethodBodyConverter, ready for the model and shape emitters described in the README there. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Pure refactor, no output change. The On Error conversion needs the statement VB's "leave the method" means when a handler falls off the end of the method but C# would otherwise carry on after its catch. Also lets it name generated locals uniquely. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Analysis only, nothing uses it yet, so no output change. * OnErrorModel: method-level statements, the active handler per statement (or "dynamic" when an On Error is nested or a jump crosses regions), and each handler's region and ways out. * OnErrorShapeSelector recognises every shape in the README; StructuredPlanner works out the structured layout, including the segmented form for re-entrant handlers (ThrowAnalysis, ReEntryGuard). * ErrUsage: one lazy pass per project for types that read Err and for Err helpers, threaded through to CommonConversions. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Emits README shape 1 for one method-level On Error GoTo whose handler exits, falls off the end, or resumes/goes to a label after the covered statements (On Error GoTo 0 ends the covered statements too). Other shapes are recognised but keep their previous output for now. * Err is maintained (catch (Exception ex) + SetProjectError, and ClearProjectError at On Error/Resume statements and when the method is left from the handler) only when ErrUsage says it's read. * Locals declared in a try and used outside it are declared before it as "= default", which is exact for VB. * By default only the statements before the first resume label are protected, so an error in cleanup code propagates. When the handler has a re-entry guard and the cleanup can throw, each segment gets its own try whose catch jumps to the handler, matching VB exactly. Changed expectations: * BasicGotoAsync: the bare catch made Err.Number read 0 at runtime; the catch now records the exception, and Err is cleared after the return value is evaluated, as VB does. * RemainingScopeIssueCharacterizationAsync: "i" is hoisted, fixing the CS0103 compile error. The automated comment-order check is skipped for tests where the shape moves code (handler before cleanup, hoisted declarations). Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Status, where each part lives (implemented vs planned), the Err read rules, and the segmented form as implemented: the handler sits after the segments at method level and each catch jumps to it, so it needs no local function or action type. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Pure refactor, no output change: with exactly one On Error GoTo label statement there is exactly one handler. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Pins the structured output for every condition kind that counts as a re-entry guard (If/ElseIf, Select Case, While, Do Until, If()), two resume labels, Err.Number-only conditions (not a guard), cleanup that can't throw, returns of the function's return variable, local functions in a handler, Err.Raise/Err.Clear not counting as reads, and mixed hoisted declarators. Also pins the unchanged output of shapes that have no emitter yet (conditional On Error, Resume Next, On Error GoTo -1, handler label in a block, Resume, handler before its On Error, running into a handler that resumes, jumps into the handler or covered code). Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Pure refactor: splitting a declaration into a default declaration and an assignment is needed with other rules for choosing the locals, so it no longer depends on the hoisting set. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Pure refactor: MethodBodyExecutableStatementVisitor keeps its per-scope state visitor, and DecorateStatementVisitor wraps it between that and the comment conversion. Nested statements are already visited through CommentConvertingVisitor, so a decorator sees each statement at any depth without the visitor knowing why. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Pure refactor: the structured emitter's default-initializer rule moves to DefaultInitializers so the other shapes can use it, and ErrStatements.CatchClause takes an optional exception filter. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Methods whose active handler is statically resume-next keep their structure: each statement that can fail is wrapped in try/catch, locals are declared as = default before their guard, If/ElseIf conditions and loop conditions that can fail are evaluated in a guard (loops via a local function), Using/SyncLock are one resume point, and Select/For/For Each/With are one guard round the header with their statements guarded individually. A guard decorator in front of the statement visitor guards every statement at any depth. Methods the guards can't express (a label handler as well, or a failing loop condition that reads a ref parameter) keep the previous output. Existing expectations changed: ShapesWithoutAnEmitterYetKeepTheirOutputAsync no longer contains ResumeNextEverywhere (now converted, covered in OnErrorResumeNextTests), so its remaining #error character offsets shift. TriviaTests.TestCarryingOverErrorTriviaAddedByConverterAsync used On Error Resume Next only to get a converter error; it now uses On Error GoTo -1, which stays unsupported. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Conditional On Error statements record whether errors are ignored in a bool local that every guard's catch filters on. Conversion and self-verifying tests, with and without Err. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
The handler becomes a local function declared after the first On Error GoTo, and every guard's catch calls it. Resume Next only: void. Two ways out among Resume Next, Resume and leaving the method: a bool whose name says what true means (Retries, Exits); Resume jumps to a label before the guarded try. Return expr in a handler is stored in the return variable or a result local the caller returns. Locals declared later that the handler uses are declared before the function. Handlers with three ways out, Resume L / GoTo L, several handlers, a handler that is run into or captures a ref parameter, guards nested in guarded blocks, and failing loop conditions where the handler can leave keep the previous output. Existing expectation changed: HandlerThatResumesNextKeepsPendingOutputAsync (renamed HandlerThatOnlyResumesNextBecomesAVoidFunctionAsync) used to pin the #error output for Resume Next. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
…ed policy member Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
…e end VB's flow analysis says a function ending in Exit Function / Return before the handler label can't reach its end, so no final return is added. But the handler is only reached by an error, so in the try/catch output the catch falls out of the try and the method end is reachable (CS0161). Add the method-exit return when the handler can fall off the end and VB believes the end is unreachable. Covers return-variable assignment, a handler that only logs, Property Get and a Select Case handler that can fall off. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
A VB local lives for the whole method, so when the initializer of a Dim in a loop body fails, the previous iteration's value is still there. The guarded declaration was split into `int q = default; try { q = ...; }` inside the loop, re-zeroing it every iteration.
Declare the split local before the outermost loop, through the same hoisting the converter already uses for locals declared without an initializer in a loop.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Splitting a local into `T x = default;` and a guarded assignment needs the type written out. An anonymous type (or a lambda's anonymous delegate type) has no name, so `var q = default;` failed with CS8716. Each shape now declines to convert when a local it would split has such a type, keeping the previous fallback output: guarded Dims in resume next and handler function, locals hoisted out of a try in the structured shape, and locals the handler function's handler uses. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
In VB a failing Case expression resumes at the first statement of that case, and the cases after it aren't tried (checked by running VB). The converted C# skipped the whole Select. The when condition of each label whose expressions can fail moves into a local function that returns true if evaluating it fails, which keeps VB's lazy, in-order evaluation. Evaluating all case expressions up front would run side effects VB wouldn't. The pattern variable is replaced by a local holding the Select expression. A failing Select expression still skips the whole statement. Only cases that can fail are affected now: a Select whose non-constant cases are comparisons of locals is no longer guarded. Handler functions guard Select the same way, and keep the fallback when the handler can leave the method or the cases read a ref parameter, as for loop conditions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
A handler whose only way out is Resume has no planned handler-function form (HandlerFunctionPlanner.WaysOf returns null for it), so the method keeps the fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
VB's flow analysis can't tell that Resume Next and Resume don't continue, so a handler ending in a Select whose branches all resume or exit was seen as falling off its end, and the function got a trailing `ClearProjectError(); return true;` that is unreachable (CS0162). Add the trailing exit only when a syntactic check of the converted handler says its end is reachable. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Resume Next in a handler became a `return;` at the end of the void local function, so an empty resume-next handler was `void H() { return; }`. A return as the last statement of a void function does nothing, so leave it out: `void H() { }`.
Existing expectations change only by losing that return (and the blank line that the empty function no longer carries): ResumeNextHandlerBecomesAVoidLocalFunction and HandlerThatOnlyResumesNextBecomesAVoidFunction.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Cover the lambda overrides of ClearErrOnReturnRewriter (with and without a return variable) and HandlerExitRewriter, which leave a Return inside a lambda alone, and the handler function and structured planners' rejection branches (three ways out, two handlers, a guard inside a guarded block, a loop condition with a handler that exits, a handler-declared local used later, a Resume to a label before On Error). Tests only; no behaviour change. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
A local function in a struct can't use this (CS1673), so the handler function shape, and loop conditions or Case expressions moved into a local function, are only used outside struct instance members. Static members and plain guards are unaffected. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
NameGenerator only looked up symbols, which don't include labels, so a generated retry label could be named like a user label (CS0140). Look labels up too, so every generated name is unique against the method's labels. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Looking labels up for every generated name (previous commit) renamed handler functions that share the name of their handler label, e.g. Failed became Failed1, though a label and a local function don't clash in C#. Only a generated label needs to avoid the method's labels. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
…sh with another local A guarded Dim in a loop is declared before the loop, where its name is in scope of an earlier sibling block that declares a local of the same name (CS0136/CS0128). Fall back for such methods. The pre-existing hoisting without On Error has the same limitation and is out of scope. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
… try/catch Resume Done / GoTo Done with Done: after the handler was rejected by StructuredPlanner. The statements from the end of the handler's region now come after the try (unprotected, like other code after the handler), so the handler's jump to them is a fall through. Keeps the fallback when those statements could fail and the handler is written for re-entry, or are jumped into a nested block. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
With no handler ever active On Error GoTo 0 is a no-op in VB apart from clearing Err (checked by running it), but it produced #error. It now converts to ProjectData.ClearProjectError() when Err is maintained, otherwise to nothing. Inside a handler it stays a fallback because it also deactivates the handler. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Creating a lambda runs none of its body, so a Dim of one needs no guard. Guarding it forced the fallback because the anonymous delegate type can't be named. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Statements after a Resume Next or Exit in a handler can never run, but were repeated after the function's return (bool HExits() { Bar(); return false; Bar(); return true; }).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
A using whose body always returns left ProjectData.ClearProjectError() after it as unreachable code. StatementReachability now sees through using and lock. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
Checked by running both: VB runs the body with a default loop variable and never leaves the loop, the C# output skips the loop and terminates. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
…s miss Direct tests for StatementReachability (labeled, if/else, try, using, lock), ThrowAnalysis (parenthesised and Not conditions stay unguarded), HandlerFunctionPlanner (jump to the handler label from covered code), StructuredPlanner (resume label before or after On Error) and OnErrorModel.EndPointIsReachable (handler ending in a label, On Error or Exit For). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
When the handler leaves to a label after itself, the tail is only reachable from the handler, so VB's flow analysis says the end of the method is unreachable and no return was added, giving CS0161 for a Function whose tail ends reachably. Decide with the syntactic StatementReachability instead and add the method exit. Also tests the labeled, using, lock, try/catch and switch/break arms of StatementReachability directly. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
A handler that resumes to a label in the covered code, where nothing before the label can fail, got the plain structured form: only the code before the label was in the try, so the first error escaped instead of being retried. ReEntryGuard now also accepts a condition in the code after the resume label that reads something assigned there (Retry: i += 1 : If i < 3 Then Work()), which selects the exact segmented form. Without such a guard the method keeps the fallback rather than converting to different behaviour. Cleanups after a label, where the first error can come from before it, are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
When nothing is between On Error GoTo and the first label the handler resumes to, the first segment was emitted as try { } catch { goto H; }. The label is still emitted, the try isn't.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
ThrowAnalysis guarded i += 1 and i = i + 1, but the generated C# is unchecked, so such a guard can never fire. +, -, * and their compound assignments are now safe when assigned to a local and every operand is a constant, local or parameter of the same integral type (Byte to ULong), or nested arithmetic of it, so no conversion is involved. Decimal, Double, Single, /, \, Mod, ^, mixed types, fields and calls stay unsafe. Existing expectations changed because their guards disappear (the guarded statement is now emitted bare, and a loop body loses its braces when only that guard needed them): * OnErrorResumeNextTests.AssigningTheFunctionNameIsGuarded: ComputeRet += 1 * OnErrorResumeNextTests.DynamicHandlerRecordsErrAndGuardsConditionsAndLoops: n -= 1 * OnErrorResumeNextTests.LoopConditionsThatCanFailMoveToALocalFunction: n += 1 in six loops * OnErrorResumeNextTests.StatementsThatCannotFailAreNotGuarded: count = count + 1 * OnErrorResumeNextTests.StructInstanceMembersThatNeedALocalFunctionKeepTheFallback: x += 1 * OnErrorHandlerFunctionTests.RetryOrResumeNextHandlerAndConditionsAndLoops: tries += 1; one fewer retry label, so the loop condition's label is renumbered retry3 to retry2. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
A method whose handler ran On Error GoTo 0 was treated as dynamic and fell back to #error inside an otherwise converted catch. In the structured shape the catch already lets later errors propagate, so the statement is only a clear of Err when Err is maintained, otherwise nothing (VB sets Err.Number to 0 there, checked by running it). The model now says when it is dynamic only for that reason, and the selector tries the structured plan first. A handler that is also written for re-entry keeps the fallback: the segmented form would protect code that VB leaves unprotected after the handler resumed to it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
A handler that falls through into a label the covered code also jumps to, and a Resume Next handler around a For Each whose body can fail (already pinned by GuardsInsideAGuardedBlockKeepPendingOutput), are listed in the fallback list where they can be found. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
A handler that ran On Error GoTo 0 and then resumed to a label in the covered code got the plain structured form whenever something before the label could fail. The code after the label was then outside the try, so its first error escaped, although VB protects the first pass through it and only the retry is unprotected. The planner now keeps the fallback for that shape: neither the plain form nor the segmented form (which would protect the retry) is exact, and no clean form is. Cleanups after a label without the GoTo 0 are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
… region c1c64ac made ReEntryGuard count conditions in the code the handler resumes to, which TailIsReEnteredByTheHandler also reached with the tail after the handler. Ordinary tails then fell back to #error: a cleanup that tests and clears what it frees (If conn IsNot Nothing Then Close(conn) / conn = Nothing), and a tail that tests the result the handler set (If F > 1 Then Exit Function). Both converted plainly before. The tail check counts only conditions in the handler again, as before c1c64ac; the segment check keeps counting those in the resumed-to code, so the counting retry loop is still segmented. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
…look dynamic A handler that ran On Error GoTo 0 and then resumed to a label after itself fell back to #error. The check that ignores the GoTo 0 inside handlers still used the linear scan of active handlers, which carried the GoTo 0 on to the label after the handler, so the handler's own jump to it seemed to cross between regions. The scan now leaves out a GoTo 0 inside a handler when asked to, as the check does. That label is only reached by jumping and is outside the try either way, so the structured form is exact. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
… isn't over locals Tests only. adf3037 treats +, -, * and their compound assignments over locals and constants of the one integral type as unable to fail. These cases must still count as able to fail: a Long assigned from Integer arithmetic (a widening), an Integer assigned from a Long, enum locals, fields, calls, and nested or parenthesised arithmetic containing any of them. Nested and parenthesised arithmetic over locals is pinned as safe. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
…rts to nothing The comments on the handler label and on an On Error GoTo 0 that converts to nothing (Err isn't maintained) were carried back by the line-based trivia mapping into the try before it. They are now attached to the next statement of the handler, as the mapping is told those lines are already mapped. The 6ff5b34 test and the On Error GoTo 0 in a structured handler test only needed incompatibleWithAutomatedCommentTesting because of this, so they lose it. The other tests keep it: they fail for the handler being emitted before code that precedes it in the source, a hoisted declaration, or the handler function placement. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
…mp to a label can follow it The check was flow-insensitive, so a re-entrant handler that resumes to a label (`If tries < 3 Then Resume Retry`) and only then runs On Error GoTo 0 fell back to #error, although nothing is resumed to unprotected. It now counts an On Error GoTo 0 only when a Resume to a label or a GoTo is written after it, or it is in a loop, which is a syntactic check that errs towards the fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX
1 task done
Conflict in MethodBodyExecutableStatementVisitor: master added the _writeBackPlacement field and renamed the decorated visitor local to byRefParameterVisitor; this branch keeps that visitor in the _statementVisitor field so it can be re-decorated. Kept both fields and used the field. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_019FEr8FpweGikrBKYdcSCS1
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #426 for the common shapes. Shapes not yet handled keep today's
#erroroutput. They are listed in the README under "Output shapes" → 5. Fallback.Problem
On Error GoTo,On Error Resume NextandResumewere only converted in one narrow shape, and everything else got#error. VB's error handling resumes at the failing statement, often inside nested blocks. C# can'tgotointo a block or atry.Solution
The approach is to catch at the failing statement, so nothing ever jumps inwards.
CodeConverter/CSharp/OnError/README.mdhas the design, maps each requirement to the class that implements it, and records the decisions below.A model pass (
OnErrorModel) works out:ThrowAnalysis);The simplest fitting shape is then chosen:
On Error GoTo Hwhere the handler exits, falls off the end, or resumes to a labeltry/catch, or a segmented form when the handler is written for re-entryOn Error Resume Nexttry { S(); } catch { }per statement that can fail. FailingIf,Caseand loop conditions get a flag or a local function so control goes where VB sends itResumes orResume Nexts into the covered codevoid, or aboolnamed…Retriesor…ExitsOn Error Resume Nextturned on and off at runtimecatch when (resumeNext)Erris maintained withProjectData.SetProjectErrorandClearProjectErroronly when the type referencesErr, or the project has anErrhelper. A cached project pass finds those helpers. Otherwise the catches are barecatch { }.Pure refactors come first, in their own commits:
DeclarationSplitter, a statement-visitor decorator hook, and shared default initializers.Decisions already agreed
Erris maintained only when it appears to be used, as above.Guardhelper: thetry/catchis written inline.For,For EachorWithheader skips the block. VB instead runs the body once with a default variable, and loops forever on a failingStep.Resume Labelreached, propagate. The exact segmented form is used only when a re-entry guard (a retry counter or flag) is detected.Needs your attention / decision
Resume Cleanup, and the cleanup code bounds its own failures, e.g.n += 1 : If n < 3 Then Flaky(). VB re-enters the handler untilnreaches 3. The C# lets the first error propagate. Reviewer round 3 made such tails keep the#errorfallback. Round 4 found that this also broke ordinary cleanup tails (If conn IsNot Nothing Then Close(conn)), so tails went back to plain output. Telling the two apart would need another heuristic. Recommendation: keep it as is. It follows the "secondary errors propagate" rule.On Error, and some hoisted declarations move too, so 21 conversion tests setincompatibleWithAutomatedCommentTesting.FailingCaseExpressionOnABooleanSelectAsyncalso drops the comment onOn Error Resume Next. That is a separate small defect that hasn't been fixed.OnErrorStatementTests,ResumeNextEverywherewas removed from the fallback theory because it now converts. Offsets and numbering of the remaining#errorlines shifted.HandlerThatResumesNextKeepsPendingOutputAsyncbecameHandlerThatOnlyResumesNextBecomesAVoidFunctionAsync.TriviaTests.TestCarryingOverErrorTriviaAddedByConverterAsyncnow usesOn Error GoTo -1, which is still unsupported, to provoke a converter error.ThrowAnalysisnow treats integer+,-and*on locals as unable to fail, because the output is unchecked. This removed guards in six newer expectations.Out of scope (pre-existing converter bugs found during review)
HoistVariablesBeforeLoopWhenNeeded) can clash with a same-named local in an earlier block (CS0136), with or withoutOn Error. UnderOn Errorsuch methods keep the fallback for now.Withon aReadOnlyfield gives CS0192.Declined review nitpicks
void H() { }rather than an empty catch, CS0825 oncase var _ whenin the syntax tree (the text is valid), unused labels left aslabel: ;, retry labels numbered in generation order, andtry { i = 0; } catch { goto EH; }around a statement that can't fail.Testing
Full suite on net10.0, Linux: 0 failed, 1690 passed, 5 skipped. The baseline before this work was 0 failed, 1460 passed, 5 skipped, so there are no new failures and 230 new tests.
CI (Windows and Linux) is green up to cc91f6d. 4523c4e is pending.
Conversion tests are in
Tests/CSharp/StatementTests/OnError*.cs, with direct analysis tests inOnErrorAnalysisTests.cs. Self-verifying tests (the VB and the converted C# are both run and compared) are inTests/TestData/SelfVerifyingTests/VBToCS/OnError*.vb.Coverage: the changed lines in
OnError/were 100% line-covered in the last review round. The remaining uncovered branches are defensive throws, which are dead by design, and planner rejection arms.Five blind review rounds. Each reviewer verified its findings by running temporary tests. Every real finding was fixed test-first.
At least one test covering the code changed
Process
🤖 Generated with Claude Code
https://claude.ai/code/session_019FEr8GzCY8KvPQb6eDtmhX