Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly error on enum member values referring to identifiers shadow…
…ing `Infinity` and `NaN` (#55018)
- Loading branch information
Showing
6 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
25 changes: 25 additions & 0 deletions
25
tests/baselines/reference/enumShadowedInfinityNaN.errors.txt
This file contains 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,25 @@ | ||
enumShadowedInfinityNaN.ts(6,9): error TS18033: Type '{}' is not assignable to type 'number' as required for computed enum member values. | ||
enumShadowedInfinityNaN.ts(13,9): error TS18033: Type '{}' is not assignable to type 'number' as required for computed enum member values. | ||
|
||
|
||
==== enumShadowedInfinityNaN.ts (2 errors) ==== | ||
// https://github.com/microsoft/TypeScript/issues/54981 | ||
|
||
{ | ||
let Infinity = {}; | ||
enum En { | ||
X = Infinity | ||
~~~~~~~~ | ||
!!! error TS18033: Type '{}' is not assignable to type 'number' as required for computed enum member values. | ||
} | ||
} | ||
|
||
{ | ||
let NaN = {}; | ||
enum En { | ||
X = NaN | ||
~~~ | ||
!!! error TS18033: Type '{}' is not assignable to type 'number' as required for computed enum member values. | ||
} | ||
} | ||
|
This file contains 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,36 @@ | ||
//// [tests/cases/conformance/enums/enumShadowedInfinityNaN.ts] //// | ||
|
||
//// [enumShadowedInfinityNaN.ts] | ||
// https://github.com/microsoft/TypeScript/issues/54981 | ||
|
||
{ | ||
let Infinity = {}; | ||
enum En { | ||
X = Infinity | ||
} | ||
} | ||
|
||
{ | ||
let NaN = {}; | ||
enum En { | ||
X = NaN | ||
} | ||
} | ||
|
||
|
||
//// [enumShadowedInfinityNaN.js] | ||
// https://github.com/microsoft/TypeScript/issues/54981 | ||
{ | ||
var Infinity_1 = {}; | ||
var En = void 0; | ||
(function (En) { | ||
En[En["X"] = Infinity_1] = "X"; | ||
})(En || (En = {})); | ||
} | ||
{ | ||
var NaN_1 = {}; | ||
var En = void 0; | ||
(function (En) { | ||
En[En["X"] = NaN_1] = "X"; | ||
})(En || (En = {})); | ||
} |
This file contains 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,31 @@ | ||
//// [tests/cases/conformance/enums/enumShadowedInfinityNaN.ts] //// | ||
|
||
=== enumShadowedInfinityNaN.ts === | ||
// https://github.com/microsoft/TypeScript/issues/54981 | ||
|
||
{ | ||
let Infinity = {}; | ||
>Infinity : Symbol(Infinity, Decl(enumShadowedInfinityNaN.ts, 3, 5)) | ||
|
||
enum En { | ||
>En : Symbol(En, Decl(enumShadowedInfinityNaN.ts, 3, 20)) | ||
|
||
X = Infinity | ||
>X : Symbol(En.X, Decl(enumShadowedInfinityNaN.ts, 4, 11)) | ||
>Infinity : Symbol(Infinity, Decl(enumShadowedInfinityNaN.ts, 3, 5)) | ||
} | ||
} | ||
|
||
{ | ||
let NaN = {}; | ||
>NaN : Symbol(NaN, Decl(enumShadowedInfinityNaN.ts, 10, 5)) | ||
|
||
enum En { | ||
>En : Symbol(En, Decl(enumShadowedInfinityNaN.ts, 10, 15)) | ||
|
||
X = NaN | ||
>X : Symbol(En.X, Decl(enumShadowedInfinityNaN.ts, 11, 11)) | ||
>NaN : Symbol(NaN, Decl(enumShadowedInfinityNaN.ts, 10, 5)) | ||
} | ||
} | ||
|
This file contains 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,33 @@ | ||
//// [tests/cases/conformance/enums/enumShadowedInfinityNaN.ts] //// | ||
|
||
=== enumShadowedInfinityNaN.ts === | ||
// https://github.com/microsoft/TypeScript/issues/54981 | ||
|
||
{ | ||
let Infinity = {}; | ||
>Infinity : {} | ||
>{} : {} | ||
|
||
enum En { | ||
>En : En | ||
|
||
X = Infinity | ||
>X : En.X | ||
>Infinity : {} | ||
} | ||
} | ||
|
||
{ | ||
let NaN = {}; | ||
>NaN : {} | ||
>{} : {} | ||
|
||
enum En { | ||
>En : En | ||
|
||
X = NaN | ||
>X : En.X | ||
>NaN : {} | ||
} | ||
} | ||
|
This file contains 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,15 @@ | ||
// https://github.com/microsoft/TypeScript/issues/54981 | ||
|
||
{ | ||
let Infinity = {}; | ||
enum En { | ||
X = Infinity | ||
} | ||
} | ||
|
||
{ | ||
let NaN = {}; | ||
enum En { | ||
X = NaN | ||
} | ||
} |