-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Reduce intersections with conflicting privates, elaborate on reasons #37762
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
Merged
Anders Hejlsberg (ahejlsberg)
merged 7 commits into
master
from
elaborateNeverIntersections
Apr 3, 2020
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3aa4762
Elaborate on reasons for 'never' intersections
ahejlsberg 7bf375f
Accept new API baselines
ahejlsberg 3197c17
Accept new baselines
ahejlsberg a3b90b8
Add tests
ahejlsberg a4c8b6e
Merge branch 'master' into elaborateNeverIntersections
ahejlsberg 8870838
Accept new baselines
ahejlsberg 85db315
Address CR feedback
ahejlsberg 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
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
70 changes: 70 additions & 0 deletions
70
tests/baselines/reference/intersectionWithConflictingPrivates.errors.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| tests/cases/compiler/intersectionWithConflictingPrivates.ts(5,4): error TS2339: Property 'y' does not exist on type 'never'. | ||
| The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some. | ||
| tests/cases/compiler/intersectionWithConflictingPrivates.ts(6,1): error TS2322: Type '{}' is not assignable to type 'never'. | ||
| The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some. | ||
|
|
||
|
|
||
| ==== tests/cases/compiler/intersectionWithConflictingPrivates.ts (2 errors) ==== | ||
| class A { private x: unknown; y?: string; } | ||
| class B { private x: unknown; y?: string; } | ||
|
|
||
| declare let ab: A & B; | ||
| ab.y = 'hello'; | ||
| ~ | ||
| !!! error TS2339: Property 'y' does not exist on type 'never'. | ||
| !!! error TS2339: The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some. | ||
| ab = {}; | ||
| ~~ | ||
| !!! error TS2322: Type '{}' is not assignable to type 'never'. | ||
| !!! error TS2322: The intersection 'A & B' was reduced to 'never' because property 'x' exists in multiple constituents and is private in some. | ||
|
|
||
| function f1(node: A | B) { | ||
| if (node instanceof A || node instanceof A) { | ||
| node; // A | ||
| } | ||
| else { | ||
| node; // B | ||
| } | ||
| node; // A | B | ||
| } | ||
|
|
||
| // Repro from #37659 | ||
|
|
||
| abstract class ViewNode { } | ||
| abstract class ViewRefNode extends ViewNode { } | ||
| abstract class ViewRefFileNode extends ViewRefNode { } | ||
|
|
||
| class CommitFileNode extends ViewRefFileNode { | ||
| private _id: any; | ||
| } | ||
|
|
||
| class ResultsFileNode extends ViewRefFileNode { | ||
| private _id: any; | ||
| } | ||
|
|
||
| class StashFileNode extends CommitFileNode { | ||
| private _id2: any; | ||
| } | ||
|
|
||
| class StatusFileNode extends ViewNode { | ||
| private _id: any; | ||
| } | ||
|
|
||
| class Foo { | ||
| private async foo(node: CommitFileNode | ResultsFileNode | StashFileNode) { | ||
| if ( | ||
| !(node instanceof CommitFileNode) && | ||
| !(node instanceof StashFileNode) && | ||
| !(node instanceof ResultsFileNode) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| await this.bar(node); | ||
| } | ||
|
|
||
| private async bar(node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode, options?: {}) { | ||
| return Promise.resolve(undefined); | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
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.
Consider reporting more than the first conflict. Here's what I had.
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.
I looked at doing that but decided it wasn't worth the extra code and error messages. You feel strongly we need it?
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.
I was pretty back-and-forth on this. It's a few lines of code in the error case, and it can help users in the really complicated/borked situations. I don't feel that strongly about it, but it'd be a simple change.