Skip to content
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

Exclude enum/number compatibility rule from comparable relation #42472

Merged
merged 3 commits into from
Mar 6, 2021

Conversation

ahejlsberg
Copy link
Member

Fixes #42442.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Jan 24, 2021
@ahejlsberg
Copy link
Member Author

@typescript-bot test this
@typescript-bot user test this
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 24, 2021

Heya @ahejlsberg, I've started to run the extended test suite on this PR at fd1a4cb. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 24, 2021

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at fd1a4cb. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 24, 2021

Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at fd1a4cb. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@ahejlsberg
Copy link
Member Author

The only test changes related to this PR are some new errors in the RWC vscode project. All but one of them are flagging real issues. For example, code that declares something as a KeyCode[], but then compares element values to -1, which doesn't match any declared KeyCode member. So, the array declaration should really be (KeyCode | -1)[].

The one undesired new error is related to this enum declaration in vs/editor/common/modes.ts:

/**
 * Open ended enum at runtime
 * @internal
 */
export const enum LanguageId {
	Null = 0,
	PlainText = 1
}

The intent here is for LanguageId to be a numeric (i.e. non-union) enum. This can be accomplished by changing one of the enum values to a computed expression:

export const enum LanguageId {
	Null = +0,
	PlainText = 1
}

Subtle, but actually an intended and documented behavior.

@DanielRosenwasser DanielRosenwasser added the Breaking Change Would introduce errors in existing code label Jan 25, 2021
@DanielRosenwasser
Copy link
Member

This seems like almost pure goodness, but I would still err on the side of saying that this can wait for 4.3. That +0 workaround is pretty subtle.

@DanielRosenwasser
Copy link
Member

What is the case for the non-union enum? It's unclear from that example.

@DanielRosenwasser
Copy link
Member

@ahejlsberg
Copy link
Member Author

What is the case for the non-union enum? It's unclear from that example.

The code that broke compares a value of type LanguageId to the numeric value 73. I guess the intent is to create symbolic names for a few special language IDs, but otherwise allow any integer value.

@ahejlsberg
Copy link
Member Author

@sandersn sandersn added this to Not started in PR Backlog Feb 8, 2021
@ahejlsberg ahejlsberg merged commit f918bd9 into master Mar 6, 2021
PR Backlog automation moved this from Not started to Done Mar 6, 2021
@ahejlsberg ahejlsberg deleted the fix42442 branch March 6, 2021 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team Breaking Change Would introduce errors in existing code For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
PR Backlog
  
Done
Development

Successfully merging this pull request may close these issues.

Comparing numeric enum to number narrows variable to 'never'
3 participants