Avoid duplicate assignability errors on literal unions - #64595
Open
bodapatisaikrishna wants to merge 2 commits into
Open
bodapatisaikrishna wants to merge 2 commits into
bodapatisaikrishna wants to merge 2 commits into
Conversation
When a union of literals generalizes to the same base type as its constituent check, elide the redundant child diagnostic on the error chain. Fixes microsoft#63050.
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 2
Open (2)
What changed in this PR
Prevents redundant nested diagnostics when assignability checks on literal unions are generalized to the same base type, which previously caused the same assignability error to be emitted twice.
Changes:
- Adds a compiler test case covering duplicate assignability errors for literal unions (string/number/bigint).
- Adjusts relation error reporting to elide a redundant child diagnostic for assignability/comparability when it matches the outer diagnostic.
- Updates multiple .errors baselines to reflect deduplicated error chains.
| File | Description |
|---|---|
| tsc/internal/checker/relater.go | Drops a redundant child entry from the error chain when assignability/comparability diagnostics match. |
| tsc/testdata/tests/cases/compiler/literalUnionAssignabilityDoubleError.ts | New regression test reproducing the duplicate-error scenario. |
| tsc/testdata/baselines/reference/compiler/literalUnionAssignabilityDoubleError.errors.txt | New baseline verifying only one assignability error is emitted per site. |
| tsc/testdata/baselines/reference/compiler/literalUnionAssignabilityDoubleError.types | New type baseline for the added test. |
| tsc/testdata/baselines/reference/compiler/literalUnionAssignabilityDoubleError.symbols | New symbol baseline for the added test. |
| tsc/testdata/baselines/reference/compiler/literalUnionAssignabilityDoubleError.js | New emit baseline for the added test. |
| tsc/testdata/baselines/reference/compiler/typeOfOperator1.errors.txt | Baseline updated to remove duplicated nested error line. |
| tsc/testdata/baselines/reference/compiler/recursiveIndexedAccessSimplification.errors.txt | Baseline updated to remove duplicated nested error segments. |
| tsc/testdata/baselines/reference/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt | Baseline updated to remove repeated nested assignability chain lines. |
| tsc/testdata/baselines/reference/compiler/bigintPropertyName.errors.txt | Baseline updated to remove duplicated nested error line. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| } | ||
| case diagnostics.Type_0_is_not_assignable_to_type_1, | ||
| diagnostics.Type_0_is_not_comparable_to_type_1: | ||
| if r.chainArgsMatch(generalizedSourceType, targetType) { |
Comment on lines
+4860
to
+4864
| case diagnostics.Type_0_is_not_assignable_to_type_1, | ||
| diagnostics.Type_0_is_not_comparable_to_type_1: | ||
| if r.chainArgsMatch(generalizedSourceType, targetType) { | ||
| r.errorChain = r.errorChain.next | ||
| } |
Copilot stopped reviewing on behalf of
bodapatisaikrishna due to an error
October 2, 2026 16:35
This branch has not been deployed
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.

Fixes #63050.
When relation error reporting generalizes a literal union to the same base type as its constituent check, the error chain ends up emitting the exact same assignability error twice. This elides the redundant child diagnostic when its arguments match the outer error.