Skip to content

[compiler] Support optional/logical/etc within try/catch#35606

Merged
josephsavona merged 5 commits intofacebook:mainfrom
josephsavona:worktree-2026-01-22-11-41-02-orange-river
Feb 2, 2026
Merged

[compiler] Support optional/logical/etc within try/catch#35606
josephsavona merged 5 commits intofacebook:mainfrom
josephsavona:worktree-2026-01-22-11-41-02-orange-river

Conversation

@josephsavona
Copy link
Member

@josephsavona josephsavona commented Jan 22, 2026

Adds support for value terminals (optional/logical/ternary/sequence) within try/catch clauses.

Try/catch expressions insert maybe-throw terminals after each instruction, but BuildReactiveFunction's value block extraction was not expecting these terminals. The fix is to roughly treat maybe-throw similarly to goto, falling through to the continuation block, but there are a few edge cases to handle.

I've also added extensive tests, including testing that errors correctly flow to the catch handler.

@josephsavona josephsavona requested review from mofeiZ and poteto January 22, 2026 22:56
@meta-cla meta-cla bot added the CLA Signed label Jan 22, 2026
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Jan 22, 2026
@josephsavona josephsavona marked this pull request as draft January 23, 2026 00:16
@josephsavona josephsavona changed the title [compiler] Support optional/logical/etc within try/catch [wip][compiler] Support optional/logical/etc within try/catch Jan 23, 2026
@josephsavona josephsavona force-pushed the worktree-2026-01-22-11-41-02-orange-river branch 2 times, most recently from ffa4d6e to 79e188d Compare January 24, 2026 00:07
@josephsavona josephsavona force-pushed the worktree-2026-01-22-11-41-02-orange-river branch 3 times, most recently from 415755c to 037094a Compare January 26, 2026 18:02
@josephsavona josephsavona changed the title [wip][compiler] Support optional/logical/etc within try/catch [compiler] Support optional/logical/etc within try/catch Jan 26, 2026
@josephsavona josephsavona marked this pull request as ready for review January 26, 2026 18:23
Control-flow expressions such as logicals, optionals, and ternaries were not supported within try/catch. BuildReactiveFunction recursively traversed these terminals, and was not expecting their condition blocks to end in a maybe-throw terminal, which can occur due to the try/catch. The fix here is to treat the maybe-throw similarly to goto, passing through to the continuation block.
@josephsavona josephsavona force-pushed the worktree-2026-01-22-11-41-02-orange-river branch from 7647849 to 6d10319 Compare January 30, 2026 20:29
@josephsavona josephsavona force-pushed the worktree-2026-01-22-11-41-02-orange-river branch from 6d10319 to 257dc27 Compare January 30, 2026 21:04
@josephsavona josephsavona merged commit b8a6bfa into facebook:main Feb 2, 2026
18 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 2, 2026
Adds support for value terminals (optional/logical/ternary/sequence)
within try/catch clauses.

Try/catch expressions insert maybe-throw terminals after each
instruction, but BuildReactiveFunction's value block extraction was not
expecting these terminals. The fix is to roughly treat maybe-throw
similarly to goto, falling through to the continuation block, but there
are a few edge cases to handle.

I've also added extensive tests, including testing that errors correctly
flow to the catch handler.

DiffTrain build for [b8a6bfa](b8a6bfa)
github-actions bot pushed a commit that referenced this pull request Feb 2, 2026
Adds support for value terminals (optional/logical/ternary/sequence)
within try/catch clauses.

Try/catch expressions insert maybe-throw terminals after each
instruction, but BuildReactiveFunction's value block extraction was not
expecting these terminals. The fix is to roughly treat maybe-throw
similarly to goto, falling through to the continuation block, but there
are a few edge cases to handle.

I've also added extensive tests, including testing that errors correctly
flow to the catch handler.

DiffTrain build for [b8a6bfa](b8a6bfa)
josephsavona added a commit to josephsavona/react that referenced this pull request Feb 2, 2026
The previous PR (facebook#35606) handled maybe-throw terminals within value blocks, and the changes there also made BuildReactiveFunction able to handle sequential optionals. However, CollectOptionalChainDependencies doesn't yet handle sequential value blocks, like `foo(a?.b, b?.c) ?? {}`. This PR fixes the remaining case, which means we should no longer have arbitrary limitations around value blocks.
josephsavona added a commit to josephsavona/react that referenced this pull request Feb 2, 2026
The previous PR (facebook#35606) handled maybe-throw terminals within value blocks, and the changes there also made BuildReactiveFunction able to handle sequential optionals. However, CollectOptionalChainDependencies doesn't yet handle sequential value blocks, like `foo(a?.b, b?.c) ?? {}`. This PR fixes the remaining case, which means we should no longer have arbitrary limitations around value blocks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant