-
Notifications
You must be signed in to change notification settings - Fork 13k
Enforce identical enum values in compatibility checks #55924
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4b3c52b
Add test for enum compatibility between string/number enums.
DanielRosenwasser 26aa2dc
Accepted baselines.
DanielRosenwasser 35f3b9f
Add error when enum values differ.
DanielRosenwasser 41e7790
Accepted baselines.
DanielRosenwasser e476157
Rephrase error message.
DanielRosenwasser 21f2794
Update tests.
DanielRosenwasser 2db2773
Accept baselines.
DanielRosenwasser e7da702
Error on undefined values.
DanielRosenwasser b2033b3
Accept baseline.
DanielRosenwasser fad8d30
Add test cases around ambient enum members.
DanielRosenwasser 29b68f5
Accepted baselines.
DanielRosenwasser b594281
Only error on undefined values when the other is a string.
DanielRosenwasser cd2d86e
Accepted baselines.
DanielRosenwasser af7f5b8
Only do work for error reporting if there's an error reporter.
DanielRosenwasser aeeb7da
Move around comments.
DanielRosenwasser 2f075c1
Add some tests that include a bidirectional enum check.
DanielRosenwasser 91e3ac6
Accept baselines.
DanielRosenwasser 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
115 changes: 115 additions & 0 deletions
115
tests/baselines/reference/enumAssignmentCompat6.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,115 @@ | ||
f.ts(37,5): error TS2322: Type 'strings.DiagnosticCategory' is not assignable to type 'numerics.DiagnosticCategory'. | ||
Each declaration of 'DiagnosticCategory.Warning' differs in its value, where '0' was expected but '"Warning"' was given. | ||
f.ts(38,5): error TS2322: Type 'numerics.DiagnosticCategory' is not assignable to type 'strings.DiagnosticCategory'. | ||
Each declaration of 'DiagnosticCategory.Warning' differs in its value, where '"Warning"' was expected but '0' was given. | ||
f.ts(42,5): error TS2322: Type 'DiagnosticCategory' is not assignable to type 'DiagnosticCategory2'. | ||
f.ts(43,5): error TS2322: Type 'DiagnosticCategory2' is not assignable to type 'DiagnosticCategory'. | ||
f.ts(52,5): error TS2322: Type 'ambients.DiagnosticCategory' is not assignable to type 'strings.DiagnosticCategory'. | ||
One value of 'DiagnosticCategory.Warning' is the string '"Warning"', and the other is assumed to be an unknown numeric value. | ||
f.ts(53,5): error TS2322: Type 'strings.DiagnosticCategory' is not assignable to type 'ambients.DiagnosticCategory'. | ||
One value of 'DiagnosticCategory.Warning' is the string '"Warning"', and the other is assumed to be an unknown numeric value. | ||
f.ts(73,9): error TS2322: Type 'DiagnosticCategory' is not assignable to type 'import("f").DiagnosticCategory'. | ||
Each declaration of 'DiagnosticCategory.Warning' differs in its value, where '0' was expected but '"Warning"' was given. | ||
f.ts(74,9): error TS2322: Type 'import("f").DiagnosticCategory' is not assignable to type 'DiagnosticCategory'. | ||
Each declaration of 'DiagnosticCategory.Warning' differs in its value, where '"Warning"' was expected but '0' was given. | ||
|
||
|
||
==== f.ts (8 errors) ==== | ||
// @filename a.ts | ||
namespace numerics { | ||
export enum DiagnosticCategory { | ||
Warning, | ||
Error, | ||
Suggestion, | ||
Message, | ||
} | ||
|
||
export enum DiagnosticCategory2 { | ||
Warning, | ||
Error, | ||
Suggestion, | ||
Message, | ||
} | ||
} | ||
|
||
namespace strings { | ||
export enum DiagnosticCategory { | ||
Warning = "Warning", | ||
Error = "Error", | ||
Suggestion = "Suggestion", | ||
Message = "Message", | ||
} | ||
} | ||
|
||
declare namespace ambients { | ||
export enum DiagnosticCategory { | ||
Warning, | ||
Error, | ||
Suggestion, | ||
Message, | ||
} | ||
} | ||
|
||
function f(x: numerics.DiagnosticCategory, y: strings.DiagnosticCategory) { | ||
x = y; | ||
~ | ||
!!! error TS2322: Type 'strings.DiagnosticCategory' is not assignable to type 'numerics.DiagnosticCategory'. | ||
!!! error TS2322: Each declaration of 'DiagnosticCategory.Warning' differs in its value, where '0' was expected but '"Warning"' was given. | ||
y = x; | ||
~ | ||
!!! error TS2322: Type 'numerics.DiagnosticCategory' is not assignable to type 'strings.DiagnosticCategory'. | ||
!!! error TS2322: Each declaration of 'DiagnosticCategory.Warning' differs in its value, where '"Warning"' was expected but '0' was given. | ||
} | ||
|
||
function g(x: numerics.DiagnosticCategory2, y: strings.DiagnosticCategory) { | ||
x = y; | ||
~ | ||
!!! error TS2322: Type 'DiagnosticCategory' is not assignable to type 'DiagnosticCategory2'. | ||
y = x; | ||
~ | ||
!!! error TS2322: Type 'DiagnosticCategory2' is not assignable to type 'DiagnosticCategory'. | ||
} | ||
|
||
function h(x: numerics.DiagnosticCategory, y: ambients.DiagnosticCategory) { | ||
x = y; | ||
y = x; | ||
} | ||
|
||
function i(x: strings.DiagnosticCategory, y: ambients.DiagnosticCategory) { | ||
x = y; | ||
~ | ||
!!! error TS2322: Type 'ambients.DiagnosticCategory' is not assignable to type 'strings.DiagnosticCategory'. | ||
!!! error TS2322: One value of 'DiagnosticCategory.Warning' is the string '"Warning"', and the other is assumed to be an unknown numeric value. | ||
y = x; | ||
~ | ||
!!! error TS2322: Type 'strings.DiagnosticCategory' is not assignable to type 'ambients.DiagnosticCategory'. | ||
!!! error TS2322: One value of 'DiagnosticCategory.Warning' is the string '"Warning"', and the other is assumed to be an unknown numeric value. | ||
} | ||
|
||
export enum DiagnosticCategory { | ||
Warning, | ||
Error, | ||
Suggestion, | ||
Message, | ||
} | ||
|
||
export let x: DiagnosticCategory; | ||
|
||
(() => { | ||
enum DiagnosticCategory { | ||
Warning = "Warning", | ||
Error = "Error", | ||
Suggestion = "Suggestion", | ||
Message = "Message", | ||
} | ||
function f(y: DiagnosticCategory) { | ||
x = y; | ||
~ | ||
!!! error TS2322: Type 'DiagnosticCategory' is not assignable to type 'import("f").DiagnosticCategory'. | ||
!!! error TS2322: Each declaration of 'DiagnosticCategory.Warning' differs in its value, where '0' was expected but '"Warning"' was given. | ||
y = x; | ||
~ | ||
!!! error TS2322: Type 'import("f").DiagnosticCategory' is not assignable to type 'DiagnosticCategory'. | ||
!!! error TS2322: Each declaration of 'DiagnosticCategory.Warning' differs in its value, where '"Warning"' was expected but '0' was given. | ||
} | ||
})() |
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.