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

Const enum expression in Ambient enum declaration behaves differently between spec and compiler #2790

Closed
yuit opened this issue Apr 16, 2015 · 1 comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@yuit
Copy link
Contributor

yuit commented Apr 16, 2015

According to spec:

An expression is considered a constant enum expression if it is one of the following:
....
*** An identifier or property access that denotes a previously declared member in the same constant enum declaration.
....

In the Ambient Enum Declaration,

In ambient enum declarations, all values specified in enum member declarations must be classified as constant enum expressions.

However, compiler reports an error for the following code:

declare enum E {
    a = 10,
    b = a,  // Ambient enum elements can only have integer literal initializers.
    e = 10 << 2 * 8,  // error as well
}

This is contradict to what it means to be constant enum expression

@yuit yuit added the Spec Issues related to the TypeScript language specification label Apr 16, 2015
@danquirk
Copy link
Member

This sounds like a compiler bug?

@danquirk danquirk added the Bug A bug in TypeScript label Apr 16, 2015
@mhegazy mhegazy removed the Spec Issues related to the TypeScript language specification label Apr 22, 2015
jbondc added a commit to jbondc/TypeScript that referenced this issue May 10, 2015
…number expression). fixes microsoft#2790

If an invalid enum constant expression is found, continue incrementing with the last valid initialized value.
If an enum expression references another enum member, then emit a reference to the other value.
jbondc added a commit to jbondc/TypeScript that referenced this issue May 27, 2015
…number expression). fixes microsoft#2790

If an invalid enum constant expression is found, continue incrementing with the last valid initialized value.
If an enum expression references another enum member, then emit a reference to the other value.
@mhegazy mhegazy modified the milestones: TypeScript 1.7, TypeScript 1.6 Jul 1, 2015
@vladima vladima added the Fixed A PR has been merged for this issue label Sep 25, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants