fix(FUN-7): restore _currentEnv on all error paths in buildTable:firstList:row:#237
fix(FUN-7): restore _currentEnv on all error paths in buildTable:firstList:row:#237kostub wants to merge 1 commit into
Conversation
…tList:row: Three early `return nil;` paths in `-[MTMathListBuilder buildTable:firstList:row:]` skipped the `_currentEnv = oldEnv` restoration that the success path performed, leaving the builder's environment pointer stale after a parse failure. This is a latent/defensive fix — the builder aborts once `_error` is set so the leaked pointer is never read today — but restoring state on every exit path eliminates a future trap if the error-handling or builder-reuse model changes. Adds `_currentEnv = oldEnv;` before each of the three `return nil;` sites (buildInternal failure, MTParseErrorMissingEnd, and tableWithEnvironment failure). No API change, no behavior change for any existing input. Closes FUN-7 (issues.md#L243). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request updates MTMathListBuilder.m to ensure that the previous environment (oldEnv) is correctly restored to _currentEnv before returning early on error paths within the buildTable:firstList:rows: method. There are no review comments, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
EM-REVIEW v1 Scope verified via All early-return paths covered — none missed.
I grepped every Restore placement is correct. In each case No behavioral change for current inputs — confirmed reachable-observation analysis. Every nil-return from "No test" is acceptable. There is no reachable code path that observes the restored Sanity: Verdict: non-blocking. Correct, minimal, consistent. The fix makes all four exit paths symmetric and removes a latent footgun for any future code that inspects |
Summary
return nil;paths in-[MTMathListBuilder buildTable:firstList:row:]skipped the_currentEnv = oldEnvrestoration that the success path correctly performed, leaving the builder's environment pointer stale after any parse failure inside a table/matrix environment._currentEnv = oldEnv;before each of the three early returns — thebuildInternal:failure path, theMTParseErrorMissingEndpath, and thetableWithEnvironment:rows:error:failure path._erroron every error path and then unwinds without inspecting_currentEnvagain, so no current call sequence observes the leaked pointer. The fix eliminates a future trap if error-handling or builder-reuse semantics change.Closes FUN-7 (issues.md#L243).
Changes
iosMath/lib/MTMathListBuilder.m— +3 lines, 1 file, no API or behavior change.Test plan
swift build— passes (Build complete)swift test— all tests pass, 0 failures (Test Suite 'All tests' passed)MTMathListBuilderTestalready covers valid table parsing andMTParseErrorMissingEnderror cases. The leaked_currentEnvis not externally observable today (builder is single-use-per-parse, unwinds immediately on_error), so no meaningful new assertion is possible beyond confirming existing error cases still return the samenil+ error code — which the existing suite already asserts.🤖 Generated with Claude Code