[PR #731] [MERGED] fix(javascript): preserve unknown branches in primitive unions #2199

Closed
opened 2026-10-16 21:15:33 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/731
Author: @kaoru0822-kitauji
Created: 10/6/2026
Status: ✅ Merged
Merged: 10/6/2026
Merged by: @kaoru0822-kitauji

Base: main ← Head: fix/semantic-union-unknown-branches


📝 Commits (1)

  • 9a2f395 fix(javascript): preserve unknown branches in primitive unions

📊 Changes

3 files changed (+325 additions, -4 deletions)

View changed files

➕ src/application/JavaScriptReturnShapeProjection.test.ts (+166 -0)
➕ src/domain/javascriptSemanticAnalysis.unions.test.ts (+156 -0)
📝 src/domain/javascriptSemanticValues.ts (+3 -4)

📄 Description

Summary

Keep unresolved branches ambiguous when another branch contains multiple primitive alternatives.

No separate issue: this is a reproduced false definite-value result in the static semantic evaluator.

Problem and expected behavior

condition ? (choice ? "one" : "two") : missing is reported as the definite union ["one", "two"], discarding the unresolved branch. The one- and three-alternative controls correctly remain ambiguous.

The merge helper flattens the two-element union into two primitives and the unsupported branch into zero. Its candidate-count shortcut then mistakes two flattened primitives for two supported inputs.

The public export-return projection consequently emits a known union with no unknown reason where the existing contract requires uncertainty.

Change and scope

Remove only the flattened-length shortcut from mergeValues.

Require every input to be a literal or primitive union before calling the existing primitive-set constructor. Preserve its ordering/deduplication and the exact existing ambiguous result: Branches have incompatible values.

Both current callers merge two values, from conditional or logical expressions. No condition evaluator, short-circuit analysis or value-lattice expansion is added.

Contract and boundary impact

  • Semantic owner: pure AST semantic-value merging.
  • CLI/MCP: their shared analyzer/export-shape path retains unresolved information instead of a false primitive union; no tool/schema/catalog changes.
  • Evidence/provenance: projected unknown fields and existing reasons remain visible. Source locations and return-site identity stay unchanged.
  • Coverage: existing ambiguous/unknown representation is reused; no weaker fallback or invented value.
  • Provider/process/authorization/cleanup: unchanged; no code execution.
  • Generated metadata/package/installation: unchanged.

Evidence and regression coverage

On unchanged main af48fe8, the exact four-suite baseline has 44 failures and 121 passing controls. After the fix, all 165 pass.

New analyzer and public return-projection tests cover:

  • Conditional and logical branches in both orders, including reachable unresolved logical alternatives.
  • One, two and three known alternatives combined with missing identifiers, unsupported calls, objects/arrays and nonfinite results.
  • Valid literal/nested unions, duplicates, null and existing ordering.
  • Existing conservative treatment of unresolved branches, without adding short-circuit evaluation.
  • Independent multiple direct-return sites.

The public projection now preserves the existing ambiguous value status and unknown field state/value/reason for affected expressions. Tests use inert source strings and production analyzer/projection APIs.

Validation performed

  • Focused semantic analysis and return-shape suites: 165 tests passed across four files.
  • Build and npm run check: passed; all five check tasks succeeded (109 warnings, zero errors; none in changed files).
  • npm run jscpd (2.35%), npm run scan:todos, changed-file lint, and git diff --check: passed.
  • Independent review completed before publication with no blocking findings.

Node.js 24.19.0, npm 11.9.0, exact locked dependencies. Optional Turbo telemetry was disabled for local verification. Hosted CI is tracked separately; no full local-suite pass is claimed.

Compatibility, safety, and release

No schema, dependency, packaging or execution-authority changes. This is source-only analyzer and public projection coverage; no filesystem reconstruction, actual CLI/MCP process, real provider or browser was run.

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/731 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/6/2026 **Status:** ✅ Merged **Merged:** 10/6/2026 **Merged by:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Base:** `main` ← **Head:** `fix/semantic-union-unknown-branches` --- ### 📝 Commits (1) - [`9a2f395`](https://github.com/morluto/rea/commit/9a2f3950286a01922be0b07b29c4aefee466ec1e) fix(javascript): preserve unknown branches in primitive unions ### 📊 Changes **3 files changed** (+325 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `src/application/JavaScriptReturnShapeProjection.test.ts` (+166 -0) ➕ `src/domain/javascriptSemanticAnalysis.unions.test.ts` (+156 -0) 📝 `src/domain/javascriptSemanticValues.ts` (+3 -4) </details> ### 📄 Description ## Summary Keep unresolved branches ambiguous when another branch contains multiple primitive alternatives. No separate issue: this is a reproduced false definite-value result in the static semantic evaluator. ## Problem and expected behavior `condition ? (choice ? "one" : "two") : missing` is reported as the definite union `["one", "two"]`, discarding the unresolved branch. The one- and three-alternative controls correctly remain ambiguous. The merge helper flattens the two-element union into two primitives and the unsupported branch into zero. Its candidate-count shortcut then mistakes two flattened primitives for two supported inputs. The public export-return projection consequently emits a known union with no unknown reason where the existing contract requires uncertainty. ## Change and scope Remove only the flattened-length shortcut from `mergeValues`. Require every input to be a literal or primitive union before calling the existing primitive-set constructor. Preserve its ordering/deduplication and the exact existing ambiguous result: `Branches have incompatible values.` Both current callers merge two values, from conditional or logical expressions. No condition evaluator, short-circuit analysis or value-lattice expansion is added. ## Contract and boundary impact - Semantic owner: pure AST semantic-value merging. - CLI/MCP: their shared analyzer/export-shape path retains unresolved information instead of a false primitive union; no tool/schema/catalog changes. - Evidence/provenance: projected unknown fields and existing reasons remain visible. Source locations and return-site identity stay unchanged. - Coverage: existing ambiguous/unknown representation is reused; no weaker fallback or invented value. - Provider/process/authorization/cleanup: unchanged; no code execution. - Generated metadata/package/installation: unchanged. ## Evidence and regression coverage On unchanged main `af48fe8`, the exact four-suite baseline has 44 failures and 121 passing controls. After the fix, all 165 pass. New analyzer and public return-projection tests cover: - Conditional and logical branches in both orders, including reachable unresolved logical alternatives. - One, two and three known alternatives combined with missing identifiers, unsupported calls, objects/arrays and nonfinite results. - Valid literal/nested unions, duplicates, null and existing ordering. - Existing conservative treatment of unresolved branches, without adding short-circuit evaluation. - Independent multiple direct-return sites. The public projection now preserves the existing ambiguous value status and unknown field state/value/reason for affected expressions. Tests use inert source strings and production analyzer/projection APIs. ## Validation performed - Focused semantic analysis and return-shape suites: 165 tests passed across four files. - Build and `npm run check`: passed; all five check tasks succeeded (109 warnings, zero errors; none in changed files). - `npm run jscpd` (2.35%), `npm run scan:todos`, changed-file lint, and `git diff --check`: passed. - Independent review completed before publication with no blocking findings. Node.js 24.19.0, npm 11.9.0, exact locked dependencies. Optional Turbo telemetry was disabled for local verification. Hosted CI is tracked separately; no full local-suite pass is claimed. ## Compatibility, safety, and release No schema, dependency, packaging or execution-authority changes. This is source-only analyzer and public projection coverage; no filesystem reconstruction, actual CLI/MCP process, real provider or browser was run. 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-16 21:15:33 +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#2199
No description provided.