-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add a regression test for discriminating property access in parenthesized expression #51778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Andarist
wants to merge
2
commits into
microsoft:main
from
Andarist:regression-test/extra-parent-discriminate-union-narrowing
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was reporting an error before this PR: #51720
The issue was that
typeOfExpr.expressionwas passed togetDiscriminantPropertyAccesshere:https://github.com/microsoft/TypeScript/pull/50344/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R25331
and it got fixed by @ahejlsberg since he changed this and now
targetis passed there:https://github.com/microsoft/TypeScript/pull/51720/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R26520
This works since
targetis the result ofgetReferenceCandidate:https://github.com/microsoft/TypeScript/pull/50344/files#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8R25329
and that includes "skip parenthesis"-like logic:
https://github.dev/microsoft/TypeScript/blob/c124d0e2604bac1a428c24b98a1dd6508d860812/src/compiler/checker.ts#L25182-L25185
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that was an intended fix. I'm not sure we need this extra test since #51270 already includes a regression test from #51700 with two
typeofchecks that differ only in parentheses. It was in fact that difference that caused me to fix the issue.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#51720 has a test with optional chaining and parenthesis - that has worked before your PR despite the fact that the version without parenthesis reported an error. This test is kinda about the opposite situation (no optional chaining and parenthesis) - the version without parenthesis worked alright while the version with them reported an error.
I've concluded that they are slightly different and thus I've created a PR (I already had it locally as I was looking into fixing #51700 when you picked it up). I understand that they can be seen as similar enough though. Feel free to merge or close - whatever you think is best here.