-
Notifications
You must be signed in to change notification settings - Fork 12.8k
fix(46433): Unhandled Error for using "enum" as a parameter #46459
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,4 +74,3 @@ class C { m(null: string) {} } | |
> : any | ||
>string : any | ||
|
||
|
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,45 @@ | ||
tests/cases/compiler/reservedWords3.ts(1,13): error TS1390: 'enum' is not allowed as a parameter name. | ||
tests/cases/compiler/reservedWords3.ts(1,17): error TS2567: Enum declarations can only merge with namespace or other enum declarations. | ||
tests/cases/compiler/reservedWords3.ts(1,17): error TS1003: Identifier expected. | ||
tests/cases/compiler/reservedWords3.ts(2,13): error TS1390: 'class' is not allowed as a parameter name. | ||
tests/cases/compiler/reservedWords3.ts(2,18): error TS1005: '{' expected. | ||
tests/cases/compiler/reservedWords3.ts(3,13): error TS1390: 'function' is not allowed as a parameter name. | ||
tests/cases/compiler/reservedWords3.ts(3,21): error TS2567: Enum declarations can only merge with namespace or other enum declarations. | ||
tests/cases/compiler/reservedWords3.ts(3,21): error TS1003: Identifier expected. | ||
tests/cases/compiler/reservedWords3.ts(4,13): error TS1390: 'while' is not allowed as a parameter name. | ||
tests/cases/compiler/reservedWords3.ts(4,18): error TS1005: '(' expected. | ||
tests/cases/compiler/reservedWords3.ts(5,13): error TS1390: 'for' is not allowed as a parameter name. | ||
tests/cases/compiler/reservedWords3.ts(5,16): error TS1005: '(' expected. | ||
|
||
|
||
==== tests/cases/compiler/reservedWords3.ts (12 errors) ==== | ||
function f1(enum) {} | ||
~~~~ | ||
!!! error TS1390: 'enum' is not allowed as a parameter name. | ||
|
||
!!! error TS2567: Enum declarations can only merge with namespace or other enum declarations. | ||
~ | ||
!!! error TS1003: Identifier expected. | ||
function f2(class) {} | ||
~~~~~ | ||
!!! error TS1390: 'class' is not allowed as a parameter name. | ||
~ | ||
!!! error TS1005: '{' expected. | ||
function f3(function) {} | ||
~~~~~~~~ | ||
!!! error TS1390: 'function' is not allowed as a parameter name. | ||
|
||
!!! error TS2567: Enum declarations can only merge with namespace or other enum declarations. | ||
~ | ||
!!! error TS1003: Identifier expected. | ||
function f4(while) {} | ||
~~~~~ | ||
!!! error TS1390: 'while' is not allowed as a parameter name. | ||
~ | ||
!!! error TS1005: '(' expected. | ||
function f5(for) {} | ||
~~~ | ||
!!! error TS1390: 'for' is not allowed as a parameter name. | ||
~ | ||
!!! error TS1005: '(' expected. | ||
|
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,28 @@ | ||
//// [reservedWords3.ts] | ||
function f1(enum) {} | ||
function f2(class) {} | ||
function f3(function) {} | ||
function f4(while) {} | ||
function f5(for) {} | ||
|
||
|
||
//// [reservedWords3.js] | ||
function f1() { } | ||
var ; | ||
(function () { | ||
})( || ( = {})); | ||
{ } | ||
function f2() { } | ||
var default_1 = /** @class */ (function () { | ||
function default_1() { | ||
} | ||
return default_1; | ||
}()); | ||
{ } | ||
function f3() { } | ||
function () { } | ||
{ } | ||
function f4() { } | ||
while () { } | ||
function f5() { } | ||
for (;;) { } |
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,18 @@ | ||
=== tests/cases/compiler/reservedWords3.ts === | ||
function f1(enum) {} | ||
>f1 : Symbol(f1, Decl(reservedWords3.ts, 0, 0)) | ||
> : Symbol((Missing), Decl(reservedWords3.ts, 0, 12)) | ||
|
||
function f2(class) {} | ||
>f2 : Symbol(f2, Decl(reservedWords3.ts, 0, 20)) | ||
|
||
function f3(function) {} | ||
>f3 : Symbol(f3, Decl(reservedWords3.ts, 1, 21)) | ||
> : Symbol((Missing), Decl(reservedWords3.ts, 2, 12)) | ||
|
||
function f4(while) {} | ||
>f4 : Symbol(f4, Decl(reservedWords3.ts, 2, 24)) | ||
|
||
function f5(for) {} | ||
>f5 : Symbol(f5, Decl(reservedWords3.ts, 3, 21)) | ||
|
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,20 @@ | ||
=== tests/cases/compiler/reservedWords3.ts === | ||
function f1(enum) {} | ||
>f1 : () => any | ||
> : (Missing) | ||
|
||
function f2(class) {} | ||
>f2 : () => any | ||
|
||
function f3(function) {} | ||
>f3 : () => any | ||
> : () => any | ||
|
||
function f4(while) {} | ||
>f4 : () => any | ||
> : any | ||
|
||
function f5(for) {} | ||
>f5 : () => any | ||
> : any | ||
|
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 |
---|---|---|
|
@@ -10,4 +10,3 @@ var [debugger, if] = [1, 2]; | |
enum void {} | ||
function f(default: number) {} | ||
class C { m(null: string) {} } | ||
|
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,5 @@ | ||
function f1(enum) {} | ||
function f2(class) {} | ||
function f3(function) {} | ||
function f4(while) {} | ||
function f5(for) {} |
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.
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.
Was there a possible reason why we didn't do this in another PR? Maybe @JoshuaKGoldberg knows?
I'm suspicious that it had something to do with modifiers and/or contextual keywords (e.g.
public
/private
/protected
/readonly
(/override
?) on parameter properties).Otherwise the change seems good except for the fact that we bail out and start trying to parse an enum.
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 wasn't a case I considered in #43005, no.
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.
@DanielRosenwasser Yes, you are right, I thought about this case and decided to follow behavior similar to variable declarations - Playground. Where TS tries to parse the
enum
(or other keywords) keyword as a variable name and then tries to find a name for theenum
. Do we need to change that?