Improve type discrimination algorithm#1085
Merged
ahejlsberg merged 3 commits intomainfrom Jun 9, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the type discrimination algorithm in the checker, adds new tests for missing discriminants, and updates baselines for error outputs.
- Added
missingDiscriminants.tstests to cover cases where discriminants are partially missing. - Updated reference baselines under
submodule/compilerandcompilerto reflect the revised discrimination behavior. - Modified
relater.goto change howTernaryMaybeis applied within the discrimination loop.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| testdata/tests/cases/compiler/missingDiscriminants.ts | New test cases for missing discriminants behavior |
| testdata/baselines/reference/submodule/compiler/discriminateWithMissingProperty.errors.txt.diff | Cleared outdated submodule error baseline |
| testdata/baselines/reference/submodule/compiler/discriminateWithMissingProperty.errors.txt | Removed old submodule error baseline content |
| testdata/baselines/reference/compiler/missingDiscriminants.types | New type-check baseline for missing discriminants tests |
| testdata/baselines/reference/compiler/missingDiscriminants.symbols | New symbol baseline for missing discriminants tests |
| testdata/baselines/reference/compiler/missingDiscriminants.errors.txt | New error baseline for missing discriminants tests |
| internal/checker/relater.go | Adjusted discrimination logic to separate property-check and match |
Comments suppressed due to low confidence (1)
internal/checker/relater.go:1228
- The inserted closing brace here appears to end the
forloop prematurely, changing the intended nesting and control flow. Remove or reposition it so that the loop and subsequent logic maintain their original scopes.
}
jakebailey
reviewed
Jun 6, 2025
testdata/baselines/reference/submodule/compiler/discriminateWithMissingProperty.errors.txt
Show resolved
Hide resolved
Member
|
Ported it over in microsoft/TypeScript#61828 and it fails the self test. I wonder why this doesn't fail in CI here. |
Member
|
Ah, because the failure isn't in src/compiler, which is what we test here given we don't have build mode. |
jakebailey
approved these changes
Jun 9, 2025
|
The man, the myth, the legend 🫡 |
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.
Implements what I suggest here.
We might consider back-porting this to the old code base.
Fixes #1020.