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

Widening and non-widening computed enum types #52542

Merged
merged 6 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/baselines/reference/computedEnumTypeWidening.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ function f4() {
let v1 = E.B; // E2
}

const c1 = E.B;
const c2 = E.B as const;
let v1 = E.B;
let v2 = E.B as const;

class C {
p1 = E.B;
p2 = E.B as const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A readonly p3 = E.B would be another good addition, since that one should be like a const declaration, iirc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

}

// Repro from #52531

enum MyEnum { A, B, C }
Expand Down Expand Up @@ -112,6 +122,17 @@ function f4() {
var c1 = E2.B; // Fresh E2.B
var v1 = E.B; // E2
}
var c1 = E.B;
var c2 = E.B;
var v1 = E.B;
var v2 = E.B;
var C = /** @class */ (function () {
function C() {
this.p1 = E.B;
this.p2 = E.B;
}
return C;
}());
// Repro from #52531
var MyEnum;
(function (MyEnum) {
Expand Down Expand Up @@ -143,6 +164,14 @@ declare enum E2 {
D
}
declare function f4(): void;
declare const c1 = E.B;
declare const c2: E.B;
declare let v1: E;
declare let v2: E.B;
declare class C {
p1: E;
p2: E.B;
}
declare enum MyEnum {
A = 0,
B = 1,
Expand Down
91 changes: 67 additions & 24 deletions tests/baselines/reference/computedEnumTypeWidening.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -218,41 +218,84 @@ function f4() {
>B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
}

const c1 = E.B;
>c1 : Symbol(c1, Decl(computedEnumTypeWidening.ts, 53, 5))
>E.B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
>E : Symbol(E, Decl(computedEnumTypeWidening.ts, 0, 45))
>B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))

const c2 = E.B as const;
>c2 : Symbol(c2, Decl(computedEnumTypeWidening.ts, 54, 5))
>E.B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
>E : Symbol(E, Decl(computedEnumTypeWidening.ts, 0, 45))
>B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
>const : Symbol(const)

let v1 = E.B;
>v1 : Symbol(v1, Decl(computedEnumTypeWidening.ts, 55, 3))
>E.B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
>E : Symbol(E, Decl(computedEnumTypeWidening.ts, 0, 45))
>B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))

let v2 = E.B as const;
>v2 : Symbol(v2, Decl(computedEnumTypeWidening.ts, 56, 3))
>E.B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
>E : Symbol(E, Decl(computedEnumTypeWidening.ts, 0, 45))
>B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
>const : Symbol(const)

class C {
>C : Symbol(C, Decl(computedEnumTypeWidening.ts, 56, 22))

p1 = E.B;
>p1 : Symbol(C.p1, Decl(computedEnumTypeWidening.ts, 58, 9))
>E.B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
>E : Symbol(E, Decl(computedEnumTypeWidening.ts, 0, 45))
>B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))

p2 = E.B as const;
>p2 : Symbol(C.p2, Decl(computedEnumTypeWidening.ts, 59, 11))
>E.B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
>E : Symbol(E, Decl(computedEnumTypeWidening.ts, 0, 45))
>B : Symbol(E.B, Decl(computedEnumTypeWidening.ts, 3, 20))
>const : Symbol(const)
}

// Repro from #52531

enum MyEnum { A, B, C }
>MyEnum : Symbol(MyEnum, Decl(computedEnumTypeWidening.ts, 51, 1))
>A : Symbol(MyEnum.A, Decl(computedEnumTypeWidening.ts, 55, 13))
>B : Symbol(MyEnum.B, Decl(computedEnumTypeWidening.ts, 55, 16))
>C : Symbol(MyEnum.C, Decl(computedEnumTypeWidening.ts, 55, 19))
>MyEnum : Symbol(MyEnum, Decl(computedEnumTypeWidening.ts, 61, 1))
>A : Symbol(MyEnum.A, Decl(computedEnumTypeWidening.ts, 65, 13))
>B : Symbol(MyEnum.B, Decl(computedEnumTypeWidening.ts, 65, 16))
>C : Symbol(MyEnum.C, Decl(computedEnumTypeWidening.ts, 65, 19))

let val1 = MyEnum.A;
>val1 : Symbol(val1, Decl(computedEnumTypeWidening.ts, 57, 3))
>MyEnum.A : Symbol(MyEnum.A, Decl(computedEnumTypeWidening.ts, 55, 13))
>MyEnum : Symbol(MyEnum, Decl(computedEnumTypeWidening.ts, 51, 1))
>A : Symbol(MyEnum.A, Decl(computedEnumTypeWidening.ts, 55, 13))
>val1 : Symbol(val1, Decl(computedEnumTypeWidening.ts, 67, 3))
>MyEnum.A : Symbol(MyEnum.A, Decl(computedEnumTypeWidening.ts, 65, 13))
>MyEnum : Symbol(MyEnum, Decl(computedEnumTypeWidening.ts, 61, 1))
>A : Symbol(MyEnum.A, Decl(computedEnumTypeWidening.ts, 65, 13))

val1 = MyEnum.B;
>val1 : Symbol(val1, Decl(computedEnumTypeWidening.ts, 57, 3))
>MyEnum.B : Symbol(MyEnum.B, Decl(computedEnumTypeWidening.ts, 55, 16))
>MyEnum : Symbol(MyEnum, Decl(computedEnumTypeWidening.ts, 51, 1))
>B : Symbol(MyEnum.B, Decl(computedEnumTypeWidening.ts, 55, 16))
>val1 : Symbol(val1, Decl(computedEnumTypeWidening.ts, 67, 3))
>MyEnum.B : Symbol(MyEnum.B, Decl(computedEnumTypeWidening.ts, 65, 16))
>MyEnum : Symbol(MyEnum, Decl(computedEnumTypeWidening.ts, 61, 1))
>B : Symbol(MyEnum.B, Decl(computedEnumTypeWidening.ts, 65, 16))

declare enum MyDeclaredEnum { A, B, C }
>MyDeclaredEnum : Symbol(MyDeclaredEnum, Decl(computedEnumTypeWidening.ts, 58, 16))
>A : Symbol(MyDeclaredEnum.A, Decl(computedEnumTypeWidening.ts, 60, 29))
>B : Symbol(MyDeclaredEnum.B, Decl(computedEnumTypeWidening.ts, 60, 32))
>C : Symbol(MyDeclaredEnum.C, Decl(computedEnumTypeWidening.ts, 60, 35))
>MyDeclaredEnum : Symbol(MyDeclaredEnum, Decl(computedEnumTypeWidening.ts, 68, 16))
>A : Symbol(MyDeclaredEnum.A, Decl(computedEnumTypeWidening.ts, 70, 29))
>B : Symbol(MyDeclaredEnum.B, Decl(computedEnumTypeWidening.ts, 70, 32))
>C : Symbol(MyDeclaredEnum.C, Decl(computedEnumTypeWidening.ts, 70, 35))

let val2 = MyDeclaredEnum.A;
>val2 : Symbol(val2, Decl(computedEnumTypeWidening.ts, 62, 3))
>MyDeclaredEnum.A : Symbol(MyDeclaredEnum.A, Decl(computedEnumTypeWidening.ts, 60, 29))
>MyDeclaredEnum : Symbol(MyDeclaredEnum, Decl(computedEnumTypeWidening.ts, 58, 16))
>A : Symbol(MyDeclaredEnum.A, Decl(computedEnumTypeWidening.ts, 60, 29))
>val2 : Symbol(val2, Decl(computedEnumTypeWidening.ts, 72, 3))
>MyDeclaredEnum.A : Symbol(MyDeclaredEnum.A, Decl(computedEnumTypeWidening.ts, 70, 29))
>MyDeclaredEnum : Symbol(MyDeclaredEnum, Decl(computedEnumTypeWidening.ts, 68, 16))
>A : Symbol(MyDeclaredEnum.A, Decl(computedEnumTypeWidening.ts, 70, 29))

val2 = MyDeclaredEnum.B;
>val2 : Symbol(val2, Decl(computedEnumTypeWidening.ts, 62, 3))
>MyDeclaredEnum.B : Symbol(MyDeclaredEnum.B, Decl(computedEnumTypeWidening.ts, 60, 32))
>MyDeclaredEnum : Symbol(MyDeclaredEnum, Decl(computedEnumTypeWidening.ts, 58, 16))
>B : Symbol(MyDeclaredEnum.B, Decl(computedEnumTypeWidening.ts, 60, 32))
>val2 : Symbol(val2, Decl(computedEnumTypeWidening.ts, 72, 3))
>MyDeclaredEnum.B : Symbol(MyDeclaredEnum.B, Decl(computedEnumTypeWidening.ts, 70, 32))
>MyDeclaredEnum : Symbol(MyDeclaredEnum, Decl(computedEnumTypeWidening.ts, 68, 16))
>B : Symbol(MyDeclaredEnum.B, Decl(computedEnumTypeWidening.ts, 70, 32))

43 changes: 43 additions & 0 deletions tests/baselines/reference/computedEnumTypeWidening.types
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,49 @@ function f4() {
>B : E.B
}

const c1 = E.B;
>c1 : E.B
>E.B : E.B
>E : typeof E
>B : E.B

const c2 = E.B as const;
>c2 : E.B
>E.B as const : E.B
>E.B : E.B
>E : typeof E
>B : E.B

let v1 = E.B;
>v1 : E
>E.B : E.B
>E : typeof E
>B : E.B

let v2 = E.B as const;
>v2 : E.B
>E.B as const : E.B
>E.B : E.B
>E : typeof E
>B : E.B

class C {
>C : C

p1 = E.B;
>p1 : E
>E.B : E.B
>E : typeof E
>B : E.B

p2 = E.B as const;
>p2 : E.B
>E.B as const : E.B
>E.B : E.B
>E : typeof E
>B : E.B
}

// Repro from #52531

enum MyEnum { A, B, C }
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/compiler/computedEnumTypeWidening.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ function f4() {
let v1 = E.B; // E2
}

const c1 = E.B;
const c2 = E.B as const;
let v1 = E.B;
let v2 = E.B as const;

class C {
p1 = E.B;
p2 = E.B as const;
}

// Repro from #52531

enum MyEnum { A, B, C }
Expand Down