mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Added error when Enum member initaliser references itself (#34655)
Fixes #34606
This commit is contained in:
parent
edd4e0a42b
commit
4538640d8a
@ -33764,6 +33764,9 @@ namespace ts {
|
||||
error(expr, Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
error(expr, Diagnostics.Property_0_is_used_before_being_assigned, symbolToString(memberSymbol));
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
tests/cases/compiler/enumPropertyAccessBeforeInitalisation.ts(2,9): error TS2565: Property 'A' is used before being assigned.
|
||||
tests/cases/compiler/enumPropertyAccessBeforeInitalisation.ts(3,9): error TS2565: Property 'B' is used before being assigned.
|
||||
tests/cases/compiler/enumPropertyAccessBeforeInitalisation.ts(4,9): error TS2565: Property 'C' is used before being assigned.
|
||||
tests/cases/compiler/enumPropertyAccessBeforeInitalisation.ts(5,13): error TS2565: Property 'D' is used before being assigned.
|
||||
|
||||
|
||||
==== tests/cases/compiler/enumPropertyAccessBeforeInitalisation.ts (4 errors) ====
|
||||
enum E {
|
||||
A = A,
|
||||
~
|
||||
!!! error TS2565: Property 'A' is used before being assigned.
|
||||
B = E.B,
|
||||
~~~
|
||||
!!! error TS2565: Property 'B' is used before being assigned.
|
||||
C = E["C"],
|
||||
~~~~~~
|
||||
!!! error TS2565: Property 'C' is used before being assigned.
|
||||
D = 1 + D
|
||||
~
|
||||
!!! error TS2565: Property 'D' is used before being assigned.
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
//// [enumPropertyAccessBeforeInitalisation.ts]
|
||||
enum E {
|
||||
A = A,
|
||||
B = E.B,
|
||||
C = E["C"],
|
||||
D = 1 + D
|
||||
}
|
||||
|
||||
|
||||
//// [enumPropertyAccessBeforeInitalisation.js]
|
||||
var E;
|
||||
(function (E) {
|
||||
E[E["A"] = E.A] = "A";
|
||||
E[E["B"] = E.B] = "B";
|
||||
E[E["C"] = E["C"]] = "C";
|
||||
E[E["D"] = 1 + E.D] = "D";
|
||||
})(E || (E = {}));
|
||||
@ -0,0 +1,24 @@
|
||||
=== tests/cases/compiler/enumPropertyAccessBeforeInitalisation.ts ===
|
||||
enum E {
|
||||
>E : Symbol(E, Decl(enumPropertyAccessBeforeInitalisation.ts, 0, 0))
|
||||
|
||||
A = A,
|
||||
>A : Symbol(E.A, Decl(enumPropertyAccessBeforeInitalisation.ts, 0, 8))
|
||||
>A : Symbol(E.A, Decl(enumPropertyAccessBeforeInitalisation.ts, 0, 8))
|
||||
|
||||
B = E.B,
|
||||
>B : Symbol(E.B, Decl(enumPropertyAccessBeforeInitalisation.ts, 1, 10))
|
||||
>E.B : Symbol(E.B, Decl(enumPropertyAccessBeforeInitalisation.ts, 1, 10))
|
||||
>E : Symbol(E, Decl(enumPropertyAccessBeforeInitalisation.ts, 0, 0))
|
||||
>B : Symbol(E.B, Decl(enumPropertyAccessBeforeInitalisation.ts, 1, 10))
|
||||
|
||||
C = E["C"],
|
||||
>C : Symbol(E.C, Decl(enumPropertyAccessBeforeInitalisation.ts, 2, 12))
|
||||
>E : Symbol(E, Decl(enumPropertyAccessBeforeInitalisation.ts, 0, 0))
|
||||
>"C" : Symbol(E.C, Decl(enumPropertyAccessBeforeInitalisation.ts, 2, 12))
|
||||
|
||||
D = 1 + D
|
||||
>D : Symbol(E.D, Decl(enumPropertyAccessBeforeInitalisation.ts, 3, 15))
|
||||
>D : Symbol(E.D, Decl(enumPropertyAccessBeforeInitalisation.ts, 3, 15))
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
=== tests/cases/compiler/enumPropertyAccessBeforeInitalisation.ts ===
|
||||
enum E {
|
||||
>E : E
|
||||
|
||||
A = A,
|
||||
>A : E
|
||||
>A : E
|
||||
|
||||
B = E.B,
|
||||
>B : E
|
||||
>E.B : E
|
||||
>E : typeof E
|
||||
>B : E
|
||||
|
||||
C = E["C"],
|
||||
>C : E
|
||||
>E["C"] : E
|
||||
>E : typeof E
|
||||
>"C" : "C"
|
||||
|
||||
D = 1 + D
|
||||
>D : E
|
||||
>1 + D : number
|
||||
>1 : 1
|
||||
>D : E
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
enum E {
|
||||
A = A,
|
||||
B = E.B,
|
||||
C = E["C"],
|
||||
D = 1 + D
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user