[PR #2788] [MERGED] fix(javascript): keep logical assignment results uncertain for unknown values #5391

Closed
opened 2026-10-31 01:06:17 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2788
Author: @Ganesh2325
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @morluto

Base: main ← Head: fix/logical-assignment-unknown-param


📝 Commits (2)

  • c74755b fix(javascript): keep logical assignment results uncertain for unknown values
  • fd58da8 test(javascript): cover exact uninitialized logical assignments

📊 Changes

2 files changed (+113 additions, -2 deletions)

View changed files

➕ src/domain/javascript/javascriptSemanticAnalysis.logical_assignment.test.ts (+96 -0)
📝 src/domain/javascript/javascriptSemanticAnalysis.ts (+17 -2)

📄 Description

Fixes #2646

Problem

bindAssignment recorded the RHS of x ||= 2 / x ??= 2 as an unconditional initializer. For a parameter (plain or destructured) or a catch binding, the incoming value can survive the assignment, yet the analyzer reported both the binding and the return site as the exact literal 2.

What changed

  • src/domain/javascript/javascriptSemanticAnalysis.ts: when the target binding is a parameter or catch binding, ||= / ??= record the whole assignment expression (as &&= already does), so evaluation stays unknown. Local let/var bindings keep the existing RHS behavior (e.g. let x; x ??= 2).
  • New src/domain/javascript/javascriptSemanticAnalysis.logical_assignment.test.ts: the reporter's repro (asserting the corrected result), plus ||=, ??=, &&= on plain parameters, destructured parameters and catch bindings, and controls (x = 2 stays literal 2; an unchanged parameter stays unknown).

Verification (Node 24.18.0, npm 11.16.0, npm ci)

  • New test file before the fix: 7 failed (the ||=/??= cases and the repro); after: npm run test:focused -- src/domain/javascript/javascriptSemanticAnalysis.logical_assignment.test.ts → 12 passed.
  • npx vitest run src/domain/javascript/ → 54 files, 1198 tests passed.
  • npm run verify:test-discovery → "Discovered all 1057 test files exactly once."
  • npm run lint → exit 0; npm run typecheck → exit 0.

Not covered

  • The full test suite and CLI/MCP/graph export paths were not run end to end.
  • Local bindings that hold an earlier non-literal value before ||=/??= keep the existing behavior; this change handles only caller-supplied (parameter/catch) values.

This change was prepared with AI assistance.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2788 **Author:** [@Ganesh2325](https://github.com/Ganesh2325) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/logical-assignment-unknown-param` --- ### 📝 Commits (2) - [`c74755b`](https://github.com/morluto/rea/commit/c74755be00116d4ea6ac3d89312a1fdd8142cf15) fix(javascript): keep logical assignment results uncertain for unknown values - [`fd58da8`](https://github.com/morluto/rea/commit/fd58da864305d89bc8937a7f0be80ab8f5a5dbbc) test(javascript): cover exact uninitialized logical assignments ### 📊 Changes **2 files changed** (+113 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `src/domain/javascript/javascriptSemanticAnalysis.logical_assignment.test.ts` (+96 -0) 📝 `src/domain/javascript/javascriptSemanticAnalysis.ts` (+17 -2) </details> ### 📄 Description Fixes #2646 ## Problem `bindAssignment` recorded the RHS of `x ||= 2` / `x ??= 2` as an unconditional initializer. For a parameter (plain or destructured) or a catch binding, the incoming value can survive the assignment, yet the analyzer reported both the binding and the return site as the exact literal `2`. ## What changed - `src/domain/javascript/javascriptSemanticAnalysis.ts`: when the target binding is a `parameter` or `catch` binding, `||=` / `??=` record the whole assignment expression (as `&&=` already does), so evaluation stays `unknown`. Local `let`/`var` bindings keep the existing RHS behavior (e.g. `let x; x ??= 2`). - New `src/domain/javascript/javascriptSemanticAnalysis.logical_assignment.test.ts`: the reporter's repro (asserting the corrected result), plus `||=`, `??=`, `&&=` on plain parameters, destructured parameters and catch bindings, and controls (`x = 2` stays literal `2`; an unchanged parameter stays unknown). ## Verification (Node 24.18.0, npm 11.16.0, `npm ci`) - New test file before the fix: 7 failed (the `||=`/`??=` cases and the repro); after: `npm run test:focused -- src/domain/javascript/javascriptSemanticAnalysis.logical_assignment.test.ts` → 12 passed. - `npx vitest run src/domain/javascript/` → 54 files, 1198 tests passed. - `npm run verify:test-discovery` → "Discovered all 1057 test files exactly once." - `npm run lint` → exit 0; `npm run typecheck` → exit 0. ## Not covered - The full test suite and CLI/MCP/graph export paths were not run end to end. - Local bindings that hold an earlier non-literal value before `||=`/`??=` keep the existing behavior; this change handles only caller-supplied (parameter/catch) values. This change was prepared with AI assistance. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:06:17 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5391
No description provided.