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

More helpful error message for mistakenly using : instead of = in Enum #838

Closed
chrisbubernak opened this issue Oct 6, 2014 · 1 comment · Fixed by #33336
Closed

More helpful error message for mistakenly using : instead of = in Enum #838

chrisbubernak opened this issue Oct 6, 2014 · 1 comment · Fixed by #33336
Labels
Milestone

Comments

@chrisbubernak
Copy link
Contributor

@chrisbubernak chrisbubernak commented Oct 6, 2014

In the following test case the compiler gives an error message about expecting a comma. What I believe is going on here is that a ":" is mistakenly being used instead of a an "=". It might make sense to return this suggestion to the user instead of the more generic error that a comma is expected.

==== tests/cases/conformance/parser/ecmascript5/EnumDeclarations/parserEnum5.ts (3 errors) ====
enum E2 { a, }
enum E3 { a: 1, }
!!! error TS1005: ',' expected.
enum E1 { a, b: 1, c, d: 2 = 3 }
!!! error TS1005: ',' expected.
!!! error TS1005: ',' expected.

@danquirk danquirk added the Suggestion label Oct 6, 2014
@mhegazy mhegazy added Bug help wanted and removed Suggestion labels Dec 8, 2015
@mhegazy mhegazy added this to the Community milestone Dec 8, 2015
@begincalendar

This comment has been minimized.

Copy link
Contributor

@begincalendar begincalendar commented Dec 13, 2018

As of fecbdb68bd1230757cd35f63397af006926edfa5, this is the relevant call stack:

parseExpected (/usr/local/src/typescript/src/compiler/parser.ts:1192)
parseDelimitedList (/usr/local/src/typescript/src/compiler/parser.ts:2071)
parseEnumDeclaration (/usr/local/src/typescript/src/compiler/parser.ts:5958)
parseDeclarationWorker (/usr/local/src/typescript/src/compiler/parser.ts:5406)
parseDeclaration (/usr/local/src/typescript/src/compiler/parser.ts:5387)
parseStatement (/usr/local/src/typescript/src/compiler/parser.ts:5365)
parseListElement (/usr/local/src/typescript/src/compiler/parser.ts:1716)
parseList (/usr/local/src/typescript/src/compiler/parser.ts:1695)
parseSourceFileWorker (/usr/local/src/typescript/src/compiler/parser.ts:844)
parseSourceFile (/usr/local/src/typescript/src/compiler/parser.ts:699)
createSourceFile (/usr/local/src/typescript/src/compiler/parser.ts:517)
getSourceFile (/usr/local/src/typescript/src/compiler/program.ts:97)
findSourceFile (/usr/local/src/typescript/src/compiler/program.ts:2257)
(anonymous function) (/usr/local/src/typescript/src/compiler/program.ts:2157)
getSourceFileFromReferenceWorker (/usr/local/src/typescript/src/compiler/program.ts:2122)
processSourceFile (/usr/local/src/typescript/src/compiler/program.ts:2156)
processRootFile (/usr/local/src/typescript/src/compiler/program.ts:1966)
(anonymous function) (/usr/local/src/typescript/src/compiler/program.ts:824)
forEach (/usr/local/src/typescript/src/compiler/core.ts:211)
createProgram (/usr/local/src/typescript/src/compiler/program.ts:824)
performCompilation (/usr/local/src/typescript/src/tsc/tsc.ts:247)
executeCommandLine (/usr/local/src/typescript/src/tsc/tsc.ts:166)
(anonymous function) (/usr/local/src/typescript/src/tsc/tsc.ts:397)
Module._compile (loader.js:686)
Module._extensions..js (loader.js:700)
Module.load (loader.js:599)
tryModuleLoad (loader.js:538)
Module._load (loader.js:530)
Module.runMain (loader.js:742)
startup (node.js:236)
bootstrapNodeJSCore (node.js:560)

What I believe is going on here is that a ":" is mistakenly being used instead of a an "=".

Although it looks that way for your provided examples, it's not the case.

It might make sense to return this suggestion to the user instead of the more generic error that a comma is expected.

While I agree that the error message is not intuitive for your provided examples, if we have code such as:

enum E1 { a, b: any "hello" += 1, c, d}

...it becomes much less obvious what an intuitive error message should be.

The error message that is provided arises because the colon aborts the enum member parsing and relinquishes back to delimited list parsing (hence the expectation of a list terminator or comma).

I personally think the current behaviour is justified (based on the implementation and lack of severity of the issue), but a core team member may well have a different opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.