Skip to content

Conversation

@everettbu
Copy link

@everettbu everettbu commented Dec 13, 2025

Mirror of facebook/react#35304
Original author: tennisleng


Fixes #35205. Explicitly captures the previous value of the member expression in a temporary before the update occurs, ensuring that post-increment operations return the original value.

Your Name and others added 3 commits December 5, 2025 16:09
…ction

- Added @enableNewMutationAliasingModel:false directive to test file
- Added detailed bug documentation explaining the expected vs actual behavior
- Added test to SproutTodoFilter.ts to skip runtime evaluation (known bug)
- Generated proper .expect.md file showing compiled output

The bug demonstrates that the compiler incorrectly handles post-increment:
- Expected: [0,1,2] (value before increment)
- Actual: [1,2,3] (value after increment)
@greptile-apps
Copy link

greptile-apps bot commented Dec 13, 2025

Greptile Overview

Greptile Summary

Fixes post-increment operator compilation by explicitly capturing the pre-increment value in a separate temporary before the store operation occurs. This prevents aliasing issues where obj.property++ would incorrectly return the incremented value instead of the original value.

  • Fixed UpdateExpression handling in BuildHIR.ts by adding capturedPreviousValue temporary that loads from previousValuePlace before mutation
  • Added test case reproducing the bug where agg.count++ should return [0,1,2] but was returning [1,2,3]
  • Test added to skip list as expected output file shows incorrect behavior and may need regeneration

Confidence Score: 3/5

  • This PR is mostly safe but has one concerning issue with the test expectation file
  • The BuildHIR.ts fix correctly addresses the aliasing issue by capturing the pre-increment value. However, the .expect.md file shows incorrect compiled output (returns incremented values instead of pre-increment values), suggesting the test expectations need to be regenerated or the fix may need additional work
  • Pay close attention to bug-post-increment-assignment.expect.md - the expected output still demonstrates the bug rather than showing the correct behavior

Important Files Changed

File Analysis

Filename Score Overview
compiler/packages/babel-plugin-react-compiler/src/HIR/BuildHIR.ts 4/5 Fixed post-increment to capture pre-increment value in separate temporary, preventing aliasing issues
compiler/packages/babel-plugin-react-compiler/src/tests/fixtures/compiler/bug-post-increment-assignment.expect.md 2/5 Expected output shows incorrect behavior - needs regeneration after BuildHIR fix is complete

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +67 to +68
agg.count = agg.count + 1;
const current = agg.count;
Copy link

Choose a reason for hiding this comment

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

logic: Expected output still shows incorrect behavior: const current = agg.count assigns the incremented value (1, 2, 3) instead of pre-increment values (0, 1, 2). Expectation file may need regeneration after fix is verified.

Suggested change
agg.count = agg.count + 1;
const current = agg.count;
const current = agg.count - 1;
agg.count = agg.count + 1;
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/bug-post-increment-assignment.expect.md
Line: 67:68

Comment:
**logic:** Expected output still shows incorrect behavior: `const current = agg.count` assigns the incremented value (1, 2, 3) instead of pre-increment values (0, 1, 2). Expectation file may need regeneration after fix is verified.

```suggestion
  const current = agg.count - 1;
  agg.count = agg.count + 1;
```

How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants