[compiler] Fix for loops in try/catch#35686
Merged
josephsavona merged 4 commits intofacebook:mainfrom Feb 3, 2026
Merged
Conversation
Fix for for..in and for..of within try/catch. The logic to extract the init/test values didn't work in the presence of maybe-throw terminals. We fix that with more robust extraction of the value block values for this case, consistently flattening nested sequence expressions into a single ReactiveValue.
0c7b7ca to
f09e434
Compare
poteto
reviewed
Feb 3, 2026
| @@ -0,0 +1,113 @@ | |||
| --- | |||
| name: compiler-bug-investigator | |||
| description: "Use this agent when the developer asks to 'investigate a bug', 'debug why this fixture errors', 'understand why the compiler is failing', 'find the root cause of a compiler issue', or when they provide a code snippet that the React Compiler handles incorrectly and want to understand why. This agent is specifically for React Compiler bugs, not general React bugs.\\n\\n<example>\\nContext: User provides a code snippet that causes the compiler to error unexpectedly.\\nuser: \"Can you investigate why this code errors? function Component() { const x = a?.b; return <div>{x}</div> }\"\\nassistant: \"I'll use the compiler-bug-investigator agent to investigate this bug and find the root cause.\"\\n<Task tool call to launch compiler-bug-investigator>\\n</example>\\n\\n<example>\\nContext: User asks to debug a fixture that's producing incorrect output.\\nuser: \"Debug why the fixture error.invalid-optional-chain.js is failing\"\\nassistant: \"Let me launch the compiler-bug-investigator agent to analyze this fixture and identify the problematic compiler pass.\"\\n<Task tool call to launch compiler-bug-investigator>\\n</example>\\n\\n<example>\\nContext: User wants to understand unexpected compiler behavior.\\nuser: \"Investigate a bug - the compiler is generating wrong code for ternary expressions with side effects\"\\nassistant: \"I'll use the compiler-bug-investigator agent to systematically investigate this issue and identify the faulty compiler logic.\"\\n<Task tool call to launch compiler-bug-investigator>\\n</example>" | |||
Member
There was a problem hiding this comment.
It might be better to move the example out of the description, as it might throw off the search: https://platform.claude.com/docs/en/agents-and-tools/agent-skills/best-practices#writing-effective-descriptions
Member
Author
There was a problem hiding this comment.
Interesting. I used /agents to create this, i didn't decide specifically what to put here
Member
Author
There was a problem hiding this comment.
Updated to shrink down the description
f09e434 to
ec8e4c8
Compare
ec8e4c8 to
7e8ae2d
Compare
for loops in try/catch
github-actions bot
pushed a commit
that referenced
this pull request
Feb 3, 2026
This is a combination of a) a subagent for investigating compiler errors and b) testing that agent by fixing bugs with for loops within try/catch. My recent diffs to support maybe-throw within value blocks was incomplete and handled many cases, like optionals/logicals/etc within try/catch. However, the handling for for loops was making more assumptions and needed additional fixes. Key changes: * `maybe-throw` terminal `handler` is now nullable. PruneMaybeThrows nulls the handler for blocks that cannot throw, rather than changing to a `goto`. This preserves more information, and makes it easier for BuildReactiveFunction's visitValueBlock() to reconstruct the value blocks * Updates BuildReactiveFunction's handling of `for` init/test/update (and similar for `for..of` and `for..in`) to correctly extract value blocks. The previous logic made assumptions about the shape of the SequenceExpression which were incorrect in some cases within try/catch. The new helper extracts a flattened SequenceExpression. Supporting changes: * The agent itself (tested via this diff) * Updated the script for invoking snap to keep `compiler/` as the working directory, allowing relative paths to work more easily * Add an `--update` (`-u`) flag to `yarn snap minimize`, which updates the fixture in place w the minimized version DiffTrain build for [cd0c487](cd0c487)
github-actions bot
pushed a commit
that referenced
this pull request
Feb 3, 2026
This is a combination of a) a subagent for investigating compiler errors and b) testing that agent by fixing bugs with for loops within try/catch. My recent diffs to support maybe-throw within value blocks was incomplete and handled many cases, like optionals/logicals/etc within try/catch. However, the handling for for loops was making more assumptions and needed additional fixes. Key changes: * `maybe-throw` terminal `handler` is now nullable. PruneMaybeThrows nulls the handler for blocks that cannot throw, rather than changing to a `goto`. This preserves more information, and makes it easier for BuildReactiveFunction's visitValueBlock() to reconstruct the value blocks * Updates BuildReactiveFunction's handling of `for` init/test/update (and similar for `for..of` and `for..in`) to correctly extract value blocks. The previous logic made assumptions about the shape of the SequenceExpression which were incorrect in some cases within try/catch. The new helper extracts a flattened SequenceExpression. Supporting changes: * The agent itself (tested via this diff) * Updated the script for invoking snap to keep `compiler/` as the working directory, allowing relative paths to work more easily * Add an `--update` (`-u`) flag to `yarn snap minimize`, which updates the fixture in place w the minimized version DiffTrain build for [cd0c487](cd0c487)
4 tasks
This was referenced Feb 5, 2026
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.
This is a combination of a) a subagent for investigating compiler errors and b) testing that agent by fixing bugs with for loops within try/catch. My recent diffs to support maybe-throw within value blocks was incomplete and handled many cases, like optionals/logicals/etc within try/catch. However, the handling for for loops was making more assumptions and needed additional fixes.
Key changes:
maybe-throwterminalhandleris now nullable. PruneMaybeThrows nulls the handler for blocks that cannot throw, rather than changing to agoto. This preserves more information, and makes it easier for BuildReactiveFunction's visitValueBlock() to reconstruct the value blocksforinit/test/update (and similar forfor..ofandfor..in) to correctly extract value blocks. The previous logic made assumptions about the shape of the SequenceExpression which were incorrect in some cases within try/catch. The new helper extracts a flattened SequenceExpression.Supporting changes:
compiler/as the working directory, allowing relative paths to work more easily--update(-u) flag toyarn snap minimize, which updates the fixture in place w the minimized version