diff --git a/tests/baselines/reference/booleanLiteralTypes1.js b/tests/baselines/reference/booleanLiteralTypes1.js new file mode 100644 index 00000000000..6fb0244ac68 --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes1.js @@ -0,0 +1,171 @@ +//// [booleanLiteralTypes1.ts] +type A1 = true | false; +type A2 = false | true; + +function f1() { + var a: A1; + var a: A2; + var a: true | false; + var a: false | true; +} + +function f2(a: true | false, b: boolean) { + a = b; + b = a; +} + +function f3(a: true | false, b: true | false) { + var x = a || b; + var x = a && b; + var x = !a; +} + +function f4(t: true, f: false) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} + +declare function g(x: true): string; +declare function g(x: false): boolean; +declare function g(x: boolean): number; + +function f5(b: boolean) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} + +function f12(x: true | false) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: true | false) { + if (x === true) { + x; + } + else { + x; + } +} + +type Item = + { kind: true, a: string } | + { kind: false, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} + +//// [booleanLiteralTypes1.js] +function f1() { + var a; + var a; + var a; + var a; +} +function f2(a, b) { + a = b; + b = a; +} +function f3(a, b) { + var x = a || b; + var x = a && b; + var x = !a; +} +function f4(t, f) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} +function f5(b) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} +function f11(x) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === true) { + x; + } + else { + x; + } +} +function f20(x) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} +function f21(x) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/booleanLiteralTypes1.symbols b/tests/baselines/reference/booleanLiteralTypes1.symbols new file mode 100644 index 00000000000..ee7ab2ca674 --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes1.symbols @@ -0,0 +1,247 @@ +=== tests/cases/conformance/types/literal/booleanLiteralTypes1.ts === +type A1 = true | false; +>A1 : Symbol(A1, Decl(booleanLiteralTypes1.ts, 0, 0)) + +type A2 = false | true; +>A2 : Symbol(A2, Decl(booleanLiteralTypes1.ts, 0, 23)) + +function f1() { +>f1 : Symbol(f1, Decl(booleanLiteralTypes1.ts, 1, 23)) + + var a: A1; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 4, 7), Decl(booleanLiteralTypes1.ts, 5, 7), Decl(booleanLiteralTypes1.ts, 6, 7), Decl(booleanLiteralTypes1.ts, 7, 7)) +>A1 : Symbol(A1, Decl(booleanLiteralTypes1.ts, 0, 0)) + + var a: A2; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 4, 7), Decl(booleanLiteralTypes1.ts, 5, 7), Decl(booleanLiteralTypes1.ts, 6, 7), Decl(booleanLiteralTypes1.ts, 7, 7)) +>A2 : Symbol(A2, Decl(booleanLiteralTypes1.ts, 0, 23)) + + var a: true | false; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 4, 7), Decl(booleanLiteralTypes1.ts, 5, 7), Decl(booleanLiteralTypes1.ts, 6, 7), Decl(booleanLiteralTypes1.ts, 7, 7)) + + var a: false | true; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 4, 7), Decl(booleanLiteralTypes1.ts, 5, 7), Decl(booleanLiteralTypes1.ts, 6, 7), Decl(booleanLiteralTypes1.ts, 7, 7)) +} + +function f2(a: true | false, b: boolean) { +>f2 : Symbol(f2, Decl(booleanLiteralTypes1.ts, 8, 1)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 10, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 10, 28)) + + a = b; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 10, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 10, 28)) + + b = a; +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 10, 28)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 10, 12)) +} + +function f3(a: true | false, b: true | false) { +>f3 : Symbol(f3, Decl(booleanLiteralTypes1.ts, 13, 1)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 15, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 15, 28)) + + var x = a || b; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 16, 7), Decl(booleanLiteralTypes1.ts, 17, 7), Decl(booleanLiteralTypes1.ts, 18, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 15, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 15, 28)) + + var x = a && b; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 16, 7), Decl(booleanLiteralTypes1.ts, 17, 7), Decl(booleanLiteralTypes1.ts, 18, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 15, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 15, 28)) + + var x = !a; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 16, 7), Decl(booleanLiteralTypes1.ts, 17, 7), Decl(booleanLiteralTypes1.ts, 18, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 15, 12)) +} + +function f4(t: true, f: false) { +>f4 : Symbol(f4, Decl(booleanLiteralTypes1.ts, 19, 1)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) + + var x1 = t && f; +>x1 : Symbol(x1, Decl(booleanLiteralTypes1.ts, 22, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) + + var x2 = f && t; +>x2 : Symbol(x2, Decl(booleanLiteralTypes1.ts, 23, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) + + var x3 = t || f; +>x3 : Symbol(x3, Decl(booleanLiteralTypes1.ts, 24, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) + + var x4 = f || t; +>x4 : Symbol(x4, Decl(booleanLiteralTypes1.ts, 25, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) + + var x5 = !t; +>x5 : Symbol(x5, Decl(booleanLiteralTypes1.ts, 26, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) + + var x6 = !f; +>x6 : Symbol(x6, Decl(booleanLiteralTypes1.ts, 27, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) +} + +declare function g(x: true): string; +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 30, 19)) + +declare function g(x: false): boolean; +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 31, 19)) + +declare function g(x: boolean): number; +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 32, 19)) + +function f5(b: boolean) { +>f5 : Symbol(f5, Decl(booleanLiteralTypes1.ts, 32, 39)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 34, 12)) + + var z1 = g(true); +>z1 : Symbol(z1, Decl(booleanLiteralTypes1.ts, 35, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) + + var z2 = g(false); +>z2 : Symbol(z2, Decl(booleanLiteralTypes1.ts, 36, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) + + var z3 = g(b); +>z3 : Symbol(z3, Decl(booleanLiteralTypes1.ts, 37, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 34, 12)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes1.ts, 38, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 40, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f10(x: true | false) { +>f10 : Symbol(f10, Decl(booleanLiteralTypes1.ts, 42, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 44, 13)) + + switch (x) { +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 44, 13)) + + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { +>f11 : Symbol(f11, Decl(booleanLiteralTypes1.ts, 49, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 51, 13)) + + switch (x) { +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 51, 13)) + + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes1.ts, 38, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 51, 13)) +} + +function f12(x: true | false) { +>f12 : Symbol(f12, Decl(booleanLiteralTypes1.ts, 57, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 59, 13)) + + if (x) { +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 59, 13)) + + x; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 59, 13)) + } + else { + x; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 59, 13)) + } +} + +function f13(x: true | false) { +>f13 : Symbol(f13, Decl(booleanLiteralTypes1.ts, 66, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 68, 13)) + + if (x === true) { +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 68, 13)) + + x; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 68, 13)) + } + else { + x; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 68, 13)) + } +} + +type Item = +>Item : Symbol(Item, Decl(booleanLiteralTypes1.ts, 75, 1)) + + { kind: true, a: string } | +>kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) + + { kind: false, b: string }; +>kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 79, 5)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(booleanLiteralTypes1.ts, 79, 31)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 81, 13)) +>Item : Symbol(Item, Decl(booleanLiteralTypes1.ts, 75, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5), Decl(booleanLiteralTypes1.ts, 79, 5)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 81, 13)) +>kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5), Decl(booleanLiteralTypes1.ts, 79, 5)) + + case true: return x.a; +>x.a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 81, 13)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) + + case false: return x.b; +>x.b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 81, 13)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(booleanLiteralTypes1.ts, 86, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +>Item : Symbol(Item, Decl(booleanLiteralTypes1.ts, 75, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5), Decl(booleanLiteralTypes1.ts, 79, 5)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +>kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5), Decl(booleanLiteralTypes1.ts, 79, 5)) + + case true: return x.a; +>x.a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) + + case false: return x.b; +>x.b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes1.ts, 38, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +} diff --git a/tests/baselines/reference/booleanLiteralTypes1.types b/tests/baselines/reference/booleanLiteralTypes1.types new file mode 100644 index 00000000000..5e987b105b5 --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes1.types @@ -0,0 +1,311 @@ +=== tests/cases/conformance/types/literal/booleanLiteralTypes1.ts === +type A1 = true | false; +>A1 : true | false +>true : true +>false : false + +type A2 = false | true; +>A2 : false | true +>false : false +>true : true + +function f1() { +>f1 : () => void + + var a: A1; +>a : true | false +>A1 : true | false + + var a: A2; +>a : true | false +>A2 : false | true + + var a: true | false; +>a : true | false +>true : true +>false : false + + var a: false | true; +>a : true | false +>false : false +>true : true +} + +function f2(a: true | false, b: boolean) { +>f2 : (a: true | false, b: boolean) => void +>a : true | false +>true : true +>false : false +>b : boolean + + a = b; +>a = b : boolean +>a : true | false +>b : boolean + + b = a; +>b = a : true | false +>b : boolean +>a : true | false +} + +function f3(a: true | false, b: true | false) { +>f3 : (a: true | false, b: true | false) => void +>a : true | false +>true : true +>false : false +>b : true | false +>true : true +>false : false + + var x = a || b; +>x : true | false +>a || b : true | false +>a : true | false +>b : true | false + + var x = a && b; +>x : true | false +>a && b : true | false +>a : true | false +>b : true | false + + var x = !a; +>x : true | false +>!a : true | false +>a : true | false +} + +function f4(t: true, f: false) { +>f4 : (t: true, f: false) => void +>t : true +>true : true +>f : false +>false : false + + var x1 = t && f; +>x1 : false +>t && f : false +>t : true +>f : false + + var x2 = f && t; +>x2 : false +>f && t : false +>f : false +>t : true + + var x3 = t || f; +>x3 : true | false +>t || f : true | false +>t : true +>f : false + + var x4 = f || t; +>x4 : true +>f || t : true +>f : false +>t : true + + var x5 = !t; +>x5 : boolean +>!t : boolean +>t : true + + var x6 = !f; +>x6 : true +>!f : true +>f : false +} + +declare function g(x: true): string; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : true +>true : true + +declare function g(x: false): boolean; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : false +>false : false + +declare function g(x: boolean): number; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : boolean + +function f5(b: boolean) { +>f5 : (b: boolean) => void +>b : boolean + + var z1 = g(true); +>z1 : string +>g(true) : string +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>true : true + + var z2 = g(false); +>z2 : boolean +>g(false) : boolean +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>false : false + + var z3 = g(b); +>z3 : number +>g(b) : number +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>b : boolean +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +function f10(x: true | false) { +>f10 : (x: true | false) => string +>x : true | false +>true : true +>false : false + + switch (x) { +>x : true | false + + case true: return "true"; +>true : true +>"true" : string + + case false: return "false"; +>false : false +>"false" : string + } +} + +function f11(x: true | false) { +>f11 : (x: true | false) => string +>x : true | false +>true : true +>false : false + + switch (x) { +>x : true | false + + case true: return "true"; +>true : true +>"true" : string + + case false: return "false"; +>false : false +>"false" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: true | false) { +>f12 : (x: true | false) => void +>x : true | false +>true : true +>false : false + + if (x) { +>x : true | false + + x; +>x : true + } + else { + x; +>x : true | false + } +} + +function f13(x: true | false) { +>f13 : (x: true | false) => void +>x : true | false +>true : true +>false : false + + if (x === true) { +>x === true : boolean +>x : true | false +>true : true + + x; +>x : true + } + else { + x; +>x : false + } +} + +type Item = +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + { kind: true, a: string } | +>kind : true +>true : true +>a : string + + { kind: false, b: string }; +>kind : false +>false : false +>b : string + +function f20(x: Item) { +>f20 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string +>x : { kind: true; a: string; } | { kind: false; b: string; } +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + switch (x.kind) { +>x.kind : true | false +>x : { kind: true; a: string; } | { kind: false; b: string; } +>kind : true | false + + case true: return x.a; +>true : true +>x.a : string +>x : { kind: true; a: string; } +>a : string + + case false: return x.b; +>false : false +>x.b : string +>x : { kind: false; b: string; } +>b : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string +>x : { kind: true; a: string; } | { kind: false; b: string; } +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + switch (x.kind) { +>x.kind : true | false +>x : { kind: true; a: string; } | { kind: false; b: string; } +>kind : true | false + + case true: return x.a; +>true : true +>x.a : string +>x : { kind: true; a: string; } +>a : string + + case false: return x.b; +>false : false +>x.b : string +>x : { kind: false; b: string; } +>b : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/booleanLiteralTypes2.js b/tests/baselines/reference/booleanLiteralTypes2.js new file mode 100644 index 00000000000..7ef643593a6 --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes2.js @@ -0,0 +1,172 @@ +//// [booleanLiteralTypes2.ts] + +type A1 = true | false; +type A2 = false | true; + +function f1() { + var a: A1; + var a: A2; + var a: true | false; + var a: false | true; +} + +function f2(a: true | false, b: boolean) { + a = b; + b = a; +} + +function f3(a: true | false, b: true | false) { + var x = a || b; + var x = a && b; + var x = !a; +} + +function f4(t: true, f: false) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} + +declare function g(x: true): string; +declare function g(x: false): boolean; +declare function g(x: boolean): number; + +function f5(b: boolean) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} + +function f12(x: true | false) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: true | false) { + if (x === true) { + x; + } + else { + x; + } +} + +type Item = + { kind: true, a: string } | + { kind: false, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} + +//// [booleanLiteralTypes2.js] +function f1() { + var a; + var a; + var a; + var a; +} +function f2(a, b) { + a = b; + b = a; +} +function f3(a, b) { + var x = a || b; + var x = a && b; + var x = !a; +} +function f4(t, f) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} +function f5(b) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} +function f11(x) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === true) { + x; + } + else { + x; + } +} +function f20(x) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} +function f21(x) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/booleanLiteralTypes2.symbols b/tests/baselines/reference/booleanLiteralTypes2.symbols new file mode 100644 index 00000000000..1f64767cbb4 --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes2.symbols @@ -0,0 +1,248 @@ +=== tests/cases/conformance/types/literal/booleanLiteralTypes2.ts === + +type A1 = true | false; +>A1 : Symbol(A1, Decl(booleanLiteralTypes2.ts, 0, 0)) + +type A2 = false | true; +>A2 : Symbol(A2, Decl(booleanLiteralTypes2.ts, 1, 23)) + +function f1() { +>f1 : Symbol(f1, Decl(booleanLiteralTypes2.ts, 2, 23)) + + var a: A1; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 5, 7), Decl(booleanLiteralTypes2.ts, 6, 7), Decl(booleanLiteralTypes2.ts, 7, 7), Decl(booleanLiteralTypes2.ts, 8, 7)) +>A1 : Symbol(A1, Decl(booleanLiteralTypes2.ts, 0, 0)) + + var a: A2; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 5, 7), Decl(booleanLiteralTypes2.ts, 6, 7), Decl(booleanLiteralTypes2.ts, 7, 7), Decl(booleanLiteralTypes2.ts, 8, 7)) +>A2 : Symbol(A2, Decl(booleanLiteralTypes2.ts, 1, 23)) + + var a: true | false; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 5, 7), Decl(booleanLiteralTypes2.ts, 6, 7), Decl(booleanLiteralTypes2.ts, 7, 7), Decl(booleanLiteralTypes2.ts, 8, 7)) + + var a: false | true; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 5, 7), Decl(booleanLiteralTypes2.ts, 6, 7), Decl(booleanLiteralTypes2.ts, 7, 7), Decl(booleanLiteralTypes2.ts, 8, 7)) +} + +function f2(a: true | false, b: boolean) { +>f2 : Symbol(f2, Decl(booleanLiteralTypes2.ts, 9, 1)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 11, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 11, 28)) + + a = b; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 11, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 11, 28)) + + b = a; +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 11, 28)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 11, 12)) +} + +function f3(a: true | false, b: true | false) { +>f3 : Symbol(f3, Decl(booleanLiteralTypes2.ts, 14, 1)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 16, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 16, 28)) + + var x = a || b; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 17, 7), Decl(booleanLiteralTypes2.ts, 18, 7), Decl(booleanLiteralTypes2.ts, 19, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 16, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 16, 28)) + + var x = a && b; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 17, 7), Decl(booleanLiteralTypes2.ts, 18, 7), Decl(booleanLiteralTypes2.ts, 19, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 16, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 16, 28)) + + var x = !a; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 17, 7), Decl(booleanLiteralTypes2.ts, 18, 7), Decl(booleanLiteralTypes2.ts, 19, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 16, 12)) +} + +function f4(t: true, f: false) { +>f4 : Symbol(f4, Decl(booleanLiteralTypes2.ts, 20, 1)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) + + var x1 = t && f; +>x1 : Symbol(x1, Decl(booleanLiteralTypes2.ts, 23, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) + + var x2 = f && t; +>x2 : Symbol(x2, Decl(booleanLiteralTypes2.ts, 24, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) + + var x3 = t || f; +>x3 : Symbol(x3, Decl(booleanLiteralTypes2.ts, 25, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) + + var x4 = f || t; +>x4 : Symbol(x4, Decl(booleanLiteralTypes2.ts, 26, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) + + var x5 = !t; +>x5 : Symbol(x5, Decl(booleanLiteralTypes2.ts, 27, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) + + var x6 = !f; +>x6 : Symbol(x6, Decl(booleanLiteralTypes2.ts, 28, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) +} + +declare function g(x: true): string; +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 31, 19)) + +declare function g(x: false): boolean; +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 32, 19)) + +declare function g(x: boolean): number; +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 33, 19)) + +function f5(b: boolean) { +>f5 : Symbol(f5, Decl(booleanLiteralTypes2.ts, 33, 39)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 35, 12)) + + var z1 = g(true); +>z1 : Symbol(z1, Decl(booleanLiteralTypes2.ts, 36, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) + + var z2 = g(false); +>z2 : Symbol(z2, Decl(booleanLiteralTypes2.ts, 37, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) + + var z3 = g(b); +>z3 : Symbol(z3, Decl(booleanLiteralTypes2.ts, 38, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 35, 12)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes2.ts, 39, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 41, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f10(x: true | false) { +>f10 : Symbol(f10, Decl(booleanLiteralTypes2.ts, 43, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 45, 13)) + + switch (x) { +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 45, 13)) + + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { +>f11 : Symbol(f11, Decl(booleanLiteralTypes2.ts, 50, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 52, 13)) + + switch (x) { +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 52, 13)) + + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes2.ts, 39, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 52, 13)) +} + +function f12(x: true | false) { +>f12 : Symbol(f12, Decl(booleanLiteralTypes2.ts, 58, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 60, 13)) + + if (x) { +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 60, 13)) + + x; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 60, 13)) + } + else { + x; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 60, 13)) + } +} + +function f13(x: true | false) { +>f13 : Symbol(f13, Decl(booleanLiteralTypes2.ts, 67, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 69, 13)) + + if (x === true) { +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 69, 13)) + + x; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 69, 13)) + } + else { + x; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 69, 13)) + } +} + +type Item = +>Item : Symbol(Item, Decl(booleanLiteralTypes2.ts, 76, 1)) + + { kind: true, a: string } | +>kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) + + { kind: false, b: string }; +>kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 80, 5)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(booleanLiteralTypes2.ts, 80, 31)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 82, 13)) +>Item : Symbol(Item, Decl(booleanLiteralTypes2.ts, 76, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5), Decl(booleanLiteralTypes2.ts, 80, 5)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 82, 13)) +>kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5), Decl(booleanLiteralTypes2.ts, 80, 5)) + + case true: return x.a; +>x.a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 82, 13)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) + + case false: return x.b; +>x.b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 82, 13)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(booleanLiteralTypes2.ts, 87, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +>Item : Symbol(Item, Decl(booleanLiteralTypes2.ts, 76, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5), Decl(booleanLiteralTypes2.ts, 80, 5)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +>kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5), Decl(booleanLiteralTypes2.ts, 80, 5)) + + case true: return x.a; +>x.a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) + + case false: return x.b; +>x.b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes2.ts, 39, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +} diff --git a/tests/baselines/reference/booleanLiteralTypes2.types b/tests/baselines/reference/booleanLiteralTypes2.types new file mode 100644 index 00000000000..a1d7ee2d36f --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes2.types @@ -0,0 +1,312 @@ +=== tests/cases/conformance/types/literal/booleanLiteralTypes2.ts === + +type A1 = true | false; +>A1 : true | false +>true : true +>false : false + +type A2 = false | true; +>A2 : false | true +>false : false +>true : true + +function f1() { +>f1 : () => void + + var a: A1; +>a : true | false +>A1 : true | false + + var a: A2; +>a : true | false +>A2 : false | true + + var a: true | false; +>a : true | false +>true : true +>false : false + + var a: false | true; +>a : true | false +>false : false +>true : true +} + +function f2(a: true | false, b: boolean) { +>f2 : (a: true | false, b: boolean) => void +>a : true | false +>true : true +>false : false +>b : boolean + + a = b; +>a = b : boolean +>a : true | false +>b : boolean + + b = a; +>b = a : true | false +>b : boolean +>a : true | false +} + +function f3(a: true | false, b: true | false) { +>f3 : (a: true | false, b: true | false) => void +>a : true | false +>true : true +>false : false +>b : true | false +>true : true +>false : false + + var x = a || b; +>x : true | false +>a || b : true | false +>a : true | false +>b : true | false + + var x = a && b; +>x : true | false +>a && b : true | false +>a : true | false +>b : true | false + + var x = !a; +>x : true | false +>!a : true | false +>a : false | true +} + +function f4(t: true, f: false) { +>f4 : (t: true, f: false) => void +>t : true +>true : true +>f : false +>false : false + + var x1 = t && f; +>x1 : false +>t && f : false +>t : true +>f : false + + var x2 = f && t; +>x2 : false +>f && t : false +>f : false +>t : true + + var x3 = t || f; +>x3 : true +>t || f : true +>t : true +>f : false + + var x4 = f || t; +>x4 : true +>f || t : true +>f : false +>t : true + + var x5 = !t; +>x5 : false +>!t : false +>t : true + + var x6 = !f; +>x6 : true +>!f : true +>f : false +} + +declare function g(x: true): string; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : true +>true : true + +declare function g(x: false): boolean; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : false +>false : false + +declare function g(x: boolean): number; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : boolean + +function f5(b: boolean) { +>f5 : (b: boolean) => void +>b : boolean + + var z1 = g(true); +>z1 : string +>g(true) : string +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>true : true + + var z2 = g(false); +>z2 : boolean +>g(false) : boolean +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>false : false + + var z3 = g(b); +>z3 : number +>g(b) : number +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>b : boolean +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +function f10(x: true | false) { +>f10 : (x: true | false) => string +>x : true | false +>true : true +>false : false + + switch (x) { +>x : true | false + + case true: return "true"; +>true : true +>"true" : string + + case false: return "false"; +>false : false +>"false" : string + } +} + +function f11(x: true | false) { +>f11 : (x: true | false) => string +>x : true | false +>true : true +>false : false + + switch (x) { +>x : true | false + + case true: return "true"; +>true : true +>"true" : string + + case false: return "false"; +>false : false +>"false" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: true | false) { +>f12 : (x: true | false) => void +>x : true | false +>true : true +>false : false + + if (x) { +>x : true | false + + x; +>x : true + } + else { + x; +>x : false + } +} + +function f13(x: true | false) { +>f13 : (x: true | false) => void +>x : true | false +>true : true +>false : false + + if (x === true) { +>x === true : boolean +>x : true | false +>true : true + + x; +>x : true + } + else { + x; +>x : false + } +} + +type Item = +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + { kind: true, a: string } | +>kind : true +>true : true +>a : string + + { kind: false, b: string }; +>kind : false +>false : false +>b : string + +function f20(x: Item) { +>f20 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string +>x : { kind: true; a: string; } | { kind: false; b: string; } +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + switch (x.kind) { +>x.kind : true | false +>x : { kind: true; a: string; } | { kind: false; b: string; } +>kind : true | false + + case true: return x.a; +>true : true +>x.a : string +>x : { kind: true; a: string; } +>a : string + + case false: return x.b; +>false : false +>x.b : string +>x : { kind: false; b: string; } +>b : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string +>x : { kind: true; a: string; } | { kind: false; b: string; } +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + switch (x.kind) { +>x.kind : true | false +>x : { kind: true; a: string; } | { kind: false; b: string; } +>kind : true | false + + case true: return x.a; +>true : true +>x.a : string +>x : { kind: true; a: string; } +>a : string + + case false: return x.b; +>false : false +>x.b : string +>x : { kind: false; b: string; } +>b : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/enumLiteralTypes1.js b/tests/baselines/reference/enumLiteralTypes1.js new file mode 100644 index 00000000000..714227f4d60 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes1.js @@ -0,0 +1,205 @@ +//// [enumLiteralTypes1.ts] +const enum Choice { Unknown, Yes, No }; + +type YesNo = Choice.Yes | Choice.No; +type NoYes = Choice.No | Choice.Yes; +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + +function f1() { + var a: YesNo; + var a: NoYes; + var a: Choice.Yes | Choice.No; + var a: Choice.No | Choice.Yes; +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { + b = a; + c = a; + c = b; +} + +function f3(a: Choice.Yes, b: YesNo) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: Choice.Yes, b: YesNo) { + a++; + b++; +} + +declare function g(x: Choice.Yes): string; +declare function g(x: Choice.No): boolean; +declare function g(x: Choice): number; + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { + var z1 = g(Choice.Yes); + var z2 = g(Choice.No); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } +} + +function f11(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } + return assertNever(x); +} + +function f12(x: UnknownYesNo) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: UnknownYesNo) { + if (x === Choice.Yes) { + x; + } + else { + x; + } +} + +type Item = + { kind: Choice.Yes, a: string } | + { kind: Choice.No, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } + return assertNever(x); +} + +//// [enumLiteralTypes1.js] +; +function f1() { + var a; + var a; + var a; + var a; +} +function f2(a, b, c) { + b = a; + c = a; + c = b; +} +function f3(a, b) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} +function f4(a, b) { + a++; + b++; +} +function f5(a, b, c) { + var z1 = g(1 /* Yes */); + var z2 = g(2 /* No */); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case 1 /* Yes */: return "true"; + case 2 /* No */: return "false"; + } +} +function f11(x) { + switch (x) { + case 1 /* Yes */: return "true"; + case 2 /* No */: return "false"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === 1 /* Yes */) { + x; + } + else { + x; + } +} +function f20(x) { + switch (x.kind) { + case 1 /* Yes */: return x.a; + case 2 /* No */: return x.b; + } +} +function f21(x) { + switch (x.kind) { + case 1 /* Yes */: return x.a; + case 2 /* No */: return x.b; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/enumLiteralTypes1.symbols b/tests/baselines/reference/enumLiteralTypes1.symbols new file mode 100644 index 00000000000..0919f99330d --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes1.symbols @@ -0,0 +1,411 @@ +=== tests/cases/conformance/types/literal/enumLiteralTypes1.ts === +const enum Choice { Unknown, Yes, No }; +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Unknown : Symbol(Choice.Unknown, Decl(enumLiteralTypes1.ts, 0, 19)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + +type YesNo = Choice.Yes | Choice.No; +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + +type NoYes = Choice.No | Choice.Yes; +>NoYes : Symbol(NoYes, Decl(enumLiteralTypes1.ts, 2, 36)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Unknown : Symbol(Choice.Unknown, Decl(enumLiteralTypes1.ts, 0, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + +function f1() { +>f1 : Symbol(f1, Decl(enumLiteralTypes1.ts, 4, 60)) + + var a: YesNo; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 7, 7), Decl(enumLiteralTypes1.ts, 8, 7), Decl(enumLiteralTypes1.ts, 9, 7), Decl(enumLiteralTypes1.ts, 10, 7)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + var a: NoYes; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 7, 7), Decl(enumLiteralTypes1.ts, 8, 7), Decl(enumLiteralTypes1.ts, 9, 7), Decl(enumLiteralTypes1.ts, 10, 7)) +>NoYes : Symbol(NoYes, Decl(enumLiteralTypes1.ts, 2, 36)) + + var a: Choice.Yes | Choice.No; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 7, 7), Decl(enumLiteralTypes1.ts, 8, 7), Decl(enumLiteralTypes1.ts, 9, 7), Decl(enumLiteralTypes1.ts, 10, 7)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + + var a: Choice.No | Choice.Yes; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 7, 7), Decl(enumLiteralTypes1.ts, 8, 7), Decl(enumLiteralTypes1.ts, 9, 7), Decl(enumLiteralTypes1.ts, 10, 7)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { +>f2 : Symbol(f2, Decl(enumLiteralTypes1.ts, 11, 1)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 13, 12)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 13, 21)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 13, 38)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) + + b = a; +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 13, 21)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 13, 12)) + + c = a; +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 13, 38)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 13, 12)) + + c = b; +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 13, 38)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 13, 21)) +} + +function f3(a: Choice.Yes, b: YesNo) { +>f3 : Symbol(f3, Decl(enumLiteralTypes1.ts, 17, 1)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + var x = a + b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a - b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a * b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a / b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a % b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a | b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a & b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a ^ b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = -b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = ~b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a == b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a != b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a === b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a !== b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a > b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a < b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a >= b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a <= b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = !b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) +} + +function f4(a: Choice.Yes, b: YesNo) { +>f4 : Symbol(f4, Decl(enumLiteralTypes1.ts, 39, 1)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 41, 12)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 41, 26)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + a++; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 41, 12)) + + b++; +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 41, 26)) +} + +declare function g(x: Choice.Yes): string; +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 46, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + +declare function g(x: Choice.No): boolean; +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 47, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + +declare function g(x: Choice): number; +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 48, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { +>f5 : Symbol(f5, Decl(enumLiteralTypes1.ts, 48, 38)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 50, 12)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 50, 21)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 50, 38)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) + + var z1 = g(Choice.Yes); +>z1 : Symbol(z1, Decl(enumLiteralTypes1.ts, 51, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + + var z2 = g(Choice.No); +>z2 : Symbol(z2, Decl(enumLiteralTypes1.ts, 52, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + + var z3 = g(a); +>z3 : Symbol(z3, Decl(enumLiteralTypes1.ts, 53, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 50, 12)) + + var z4 = g(b); +>z4 : Symbol(z4, Decl(enumLiteralTypes1.ts, 54, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 50, 21)) + + var z5 = g(c); +>z5 : Symbol(z5, Decl(enumLiteralTypes1.ts, 55, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 50, 38)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes1.ts, 56, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 58, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f10(x: YesNo) { +>f10 : Symbol(f10, Decl(enumLiteralTypes1.ts, 60, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 62, 13)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + switch (x) { +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 62, 13)) + + case Choice.Yes: return "true"; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + + case Choice.No: return "false"; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + } +} + +function f11(x: YesNo) { +>f11 : Symbol(f11, Decl(enumLiteralTypes1.ts, 67, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 69, 13)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + switch (x) { +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 69, 13)) + + case Choice.Yes: return "true"; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + + case Choice.No: return "false"; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes1.ts, 56, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 69, 13)) +} + +function f12(x: UnknownYesNo) { +>f12 : Symbol(f12, Decl(enumLiteralTypes1.ts, 75, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 77, 13)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) + + if (x) { +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 77, 13)) + + x; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 77, 13)) + } + else { + x; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 77, 13)) + } +} + +function f13(x: UnknownYesNo) { +>f13 : Symbol(f13, Decl(enumLiteralTypes1.ts, 84, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 86, 13)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) + + if (x === Choice.Yes) { +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 86, 13)) +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + + x; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 86, 13)) + } + else { + x; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 86, 13)) + } +} + +type Item = +>Item : Symbol(Item, Decl(enumLiteralTypes1.ts, 93, 1)) + + { kind: Choice.Yes, a: string } | +>kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) + + { kind: Choice.No, b: string }; +>kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 97, 5)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(enumLiteralTypes1.ts, 97, 35)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 99, 13)) +>Item : Symbol(Item, Decl(enumLiteralTypes1.ts, 93, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5), Decl(enumLiteralTypes1.ts, 97, 5)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 99, 13)) +>kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5), Decl(enumLiteralTypes1.ts, 97, 5)) + + case Choice.Yes: return x.a; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>x.a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 99, 13)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) + + case Choice.No: return x.b; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>x.b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 99, 13)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(enumLiteralTypes1.ts, 104, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +>Item : Symbol(Item, Decl(enumLiteralTypes1.ts, 93, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5), Decl(enumLiteralTypes1.ts, 97, 5)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +>kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5), Decl(enumLiteralTypes1.ts, 97, 5)) + + case Choice.Yes: return x.a; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>x.a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) + + case Choice.No: return x.b; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>x.b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes1.ts, 56, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +} diff --git a/tests/baselines/reference/enumLiteralTypes1.types b/tests/baselines/reference/enumLiteralTypes1.types new file mode 100644 index 00000000000..8e1f478baaa --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes1.types @@ -0,0 +1,449 @@ +=== tests/cases/conformance/types/literal/enumLiteralTypes1.ts === +const enum Choice { Unknown, Yes, No }; +>Choice : Choice +>Unknown : Choice +>Yes : Choice +>No : Choice + +type YesNo = Choice.Yes | Choice.No; +>YesNo : Choice.Yes | Choice.No +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + +type NoYes = Choice.No | Choice.Yes; +>NoYes : Choice.No | Choice.Yes +>Choice : any +>No : Choice.No +>Choice : any +>Yes : Choice.Yes + +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>Choice : any +>Unknown : Choice.Unknown +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + +function f1() { +>f1 : () => void + + var a: YesNo; +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + var a: NoYes; +>a : Choice.Yes | Choice.No +>NoYes : Choice.No | Choice.Yes + + var a: Choice.Yes | Choice.No; +>a : Choice.Yes | Choice.No +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + + var a: Choice.No | Choice.Yes; +>a : Choice.Yes | Choice.No +>Choice : any +>No : Choice.No +>Choice : any +>Yes : Choice.Yes +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { +>f2 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>c : Choice +>Choice : Choice + + b = a; +>b = a : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>a : Choice.Yes | Choice.No + + c = a; +>c = a : Choice.Yes | Choice.No +>c : Choice +>a : Choice.Yes | Choice.No + + c = b; +>c = b : Choice.Yes | Choice.No +>c : Choice +>b : Choice.Yes | Choice.No +} + +function f3(a: Choice.Yes, b: YesNo) { +>f3 : (a: Choice.Yes, b: Choice.Yes | Choice.No) => void +>a : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>b : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + var x = a + b; +>x : number +>a + b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a - b; +>x : number +>a - b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a * b; +>x : number +>a * b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a / b; +>x : number +>a / b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a % b; +>x : number +>a % b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a | b; +>x : number +>a | b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a & b; +>x : number +>a & b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a ^ b; +>x : number +>a ^ b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = -b; +>x : number +>-b : number +>b : Choice.Yes | Choice.No + + var x = ~b; +>x : number +>~b : number +>b : Choice.Yes | Choice.No + + var y = a == b; +>y : boolean +>a == b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a != b; +>y : boolean +>a != b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a === b; +>y : boolean +>a === b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a !== b; +>y : boolean +>a !== b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a > b; +>y : boolean +>a > b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a < b; +>y : boolean +>a < b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a >= b; +>y : boolean +>a >= b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a <= b; +>y : boolean +>a <= b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = !b; +>y : boolean +>!b : boolean +>b : Choice.Yes | Choice.No +} + +function f4(a: Choice.Yes, b: YesNo) { +>f4 : (a: Choice.Yes, b: Choice.Yes | Choice.No) => void +>a : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>b : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + a++; +>a++ : number +>a : Choice.Yes + + b++; +>b++ : number +>b : Choice.Yes | Choice.No +} + +declare function g(x: Choice.Yes): string; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice.Yes +>Choice : any +>Yes : Choice.Yes + +declare function g(x: Choice.No): boolean; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice.No +>Choice : any +>No : Choice.No + +declare function g(x: Choice): number; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice +>Choice : Choice + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { +>f5 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>c : Choice +>Choice : Choice + + var z1 = g(Choice.Yes); +>z1 : string +>g(Choice.Yes) : string +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes + + var z2 = g(Choice.No); +>z2 : boolean +>g(Choice.No) : boolean +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No + + var z3 = g(a); +>z3 : number +>g(a) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>a : Choice.Yes | Choice.No + + var z4 = g(b); +>z4 : number +>g(b) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>b : Choice.Unknown | Choice.Yes | Choice.No + + var z5 = g(c); +>z5 : number +>g(c) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>c : Choice +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +function f10(x: YesNo) { +>f10 : (x: Choice.Yes | Choice.No) => string +>x : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + switch (x) { +>x : Choice.Yes | Choice.No + + case Choice.Yes: return "true"; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>"true" : string + + case Choice.No: return "false"; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>"false" : string + } +} + +function f11(x: YesNo) { +>f11 : (x: Choice.Yes | Choice.No) => string +>x : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + switch (x) { +>x : Choice.Yes | Choice.No + + case Choice.Yes: return "true"; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>"true" : string + + case Choice.No: return "false"; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>"false" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: UnknownYesNo) { +>f12 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void +>x : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + if (x) { +>x : Choice.Unknown | Choice.Yes | Choice.No + + x; +>x : Choice.Yes | Choice.No + } + else { + x; +>x : Choice.Unknown | Choice.Yes | Choice.No + } +} + +function f13(x: UnknownYesNo) { +>f13 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void +>x : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + if (x === Choice.Yes) { +>x === Choice.Yes : boolean +>x : Choice.Unknown | Choice.Yes | Choice.No +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes + + x; +>x : Choice.Yes + } + else { + x; +>x : Choice.Unknown | Choice.No + } +} + +type Item = +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + { kind: Choice.Yes, a: string } | +>kind : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>a : string + + { kind: Choice.No, b: string }; +>kind : Choice.No +>Choice : any +>No : Choice.No +>b : string + +function f20(x: Item) { +>f20 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + switch (x.kind) { +>x.kind : Choice.Yes | Choice.No +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>kind : Choice.Yes | Choice.No + + case Choice.Yes: return x.a; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>x.a : string +>x : { kind: Choice.Yes; a: string; } +>a : string + + case Choice.No: return x.b; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>x.b : string +>x : { kind: Choice.No; b: string; } +>b : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + switch (x.kind) { +>x.kind : Choice.Yes | Choice.No +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>kind : Choice.Yes | Choice.No + + case Choice.Yes: return x.a; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>x.a : string +>x : { kind: Choice.Yes; a: string; } +>a : string + + case Choice.No: return x.b; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>x.b : string +>x : { kind: Choice.No; b: string; } +>b : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/enumLiteralTypes2.js b/tests/baselines/reference/enumLiteralTypes2.js new file mode 100644 index 00000000000..0b2b6d35c53 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes2.js @@ -0,0 +1,206 @@ +//// [enumLiteralTypes2.ts] + +const enum Choice { Unknown, Yes, No }; + +type YesNo = Choice.Yes | Choice.No; +type NoYes = Choice.No | Choice.Yes; +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + +function f1() { + var a: YesNo; + var a: NoYes; + var a: Choice.Yes | Choice.No; + var a: Choice.No | Choice.Yes; +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { + b = a; + c = a; + c = b; +} + +function f3(a: Choice.Yes, b: UnknownYesNo) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: Choice.Yes, b: UnknownYesNo) { + a++; + b++; +} + +declare function g(x: Choice.Yes): string; +declare function g(x: Choice.No): boolean; +declare function g(x: Choice): number; + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { + var z1 = g(Choice.Yes); + var z2 = g(Choice.No); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } +} + +function f11(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } + return assertNever(x); +} + +function f12(x: UnknownYesNo) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: UnknownYesNo) { + if (x === Choice.Yes) { + x; + } + else { + x; + } +} + +type Item = + { kind: Choice.Yes, a: string } | + { kind: Choice.No, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } + return assertNever(x); +} + +//// [enumLiteralTypes2.js] +; +function f1() { + var a; + var a; + var a; + var a; +} +function f2(a, b, c) { + b = a; + c = a; + c = b; +} +function f3(a, b) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} +function f4(a, b) { + a++; + b++; +} +function f5(a, b, c) { + var z1 = g(1 /* Yes */); + var z2 = g(2 /* No */); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case 1 /* Yes */: return "true"; + case 2 /* No */: return "false"; + } +} +function f11(x) { + switch (x) { + case 1 /* Yes */: return "true"; + case 2 /* No */: return "false"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === 1 /* Yes */) { + x; + } + else { + x; + } +} +function f20(x) { + switch (x.kind) { + case 1 /* Yes */: return x.a; + case 2 /* No */: return x.b; + } +} +function f21(x) { + switch (x.kind) { + case 1 /* Yes */: return x.a; + case 2 /* No */: return x.b; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/enumLiteralTypes2.symbols b/tests/baselines/reference/enumLiteralTypes2.symbols new file mode 100644 index 00000000000..3bd937c3706 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes2.symbols @@ -0,0 +1,412 @@ +=== tests/cases/conformance/types/literal/enumLiteralTypes2.ts === + +const enum Choice { Unknown, Yes, No }; +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Unknown : Symbol(Choice.Unknown, Decl(enumLiteralTypes2.ts, 1, 19)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + +type YesNo = Choice.Yes | Choice.No; +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + +type NoYes = Choice.No | Choice.Yes; +>NoYes : Symbol(NoYes, Decl(enumLiteralTypes2.ts, 3, 36)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Unknown : Symbol(Choice.Unknown, Decl(enumLiteralTypes2.ts, 1, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + +function f1() { +>f1 : Symbol(f1, Decl(enumLiteralTypes2.ts, 5, 60)) + + var a: YesNo; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 8, 7), Decl(enumLiteralTypes2.ts, 9, 7), Decl(enumLiteralTypes2.ts, 10, 7), Decl(enumLiteralTypes2.ts, 11, 7)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) + + var a: NoYes; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 8, 7), Decl(enumLiteralTypes2.ts, 9, 7), Decl(enumLiteralTypes2.ts, 10, 7), Decl(enumLiteralTypes2.ts, 11, 7)) +>NoYes : Symbol(NoYes, Decl(enumLiteralTypes2.ts, 3, 36)) + + var a: Choice.Yes | Choice.No; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 8, 7), Decl(enumLiteralTypes2.ts, 9, 7), Decl(enumLiteralTypes2.ts, 10, 7), Decl(enumLiteralTypes2.ts, 11, 7)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + + var a: Choice.No | Choice.Yes; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 8, 7), Decl(enumLiteralTypes2.ts, 9, 7), Decl(enumLiteralTypes2.ts, 10, 7), Decl(enumLiteralTypes2.ts, 11, 7)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { +>f2 : Symbol(f2, Decl(enumLiteralTypes2.ts, 12, 1)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 14, 12)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 14, 21)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 14, 38)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) + + b = a; +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 14, 21)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 14, 12)) + + c = a; +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 14, 38)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 14, 12)) + + c = b; +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 14, 38)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 14, 21)) +} + +function f3(a: Choice.Yes, b: UnknownYesNo) { +>f3 : Symbol(f3, Decl(enumLiteralTypes2.ts, 18, 1)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) + + var x = a + b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a - b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a * b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a / b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a % b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a | b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a & b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a ^ b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = -b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = ~b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a == b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a != b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a === b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a !== b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a > b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a < b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a >= b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a <= b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = !b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) +} + +function f4(a: Choice.Yes, b: UnknownYesNo) { +>f4 : Symbol(f4, Decl(enumLiteralTypes2.ts, 40, 1)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 42, 12)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 42, 26)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) + + a++; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 42, 12)) + + b++; +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 42, 26)) +} + +declare function g(x: Choice.Yes): string; +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 47, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + +declare function g(x: Choice.No): boolean; +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 48, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + +declare function g(x: Choice): number; +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 49, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { +>f5 : Symbol(f5, Decl(enumLiteralTypes2.ts, 49, 38)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 51, 12)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 51, 21)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 51, 38)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) + + var z1 = g(Choice.Yes); +>z1 : Symbol(z1, Decl(enumLiteralTypes2.ts, 52, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + + var z2 = g(Choice.No); +>z2 : Symbol(z2, Decl(enumLiteralTypes2.ts, 53, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + + var z3 = g(a); +>z3 : Symbol(z3, Decl(enumLiteralTypes2.ts, 54, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 51, 12)) + + var z4 = g(b); +>z4 : Symbol(z4, Decl(enumLiteralTypes2.ts, 55, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 51, 21)) + + var z5 = g(c); +>z5 : Symbol(z5, Decl(enumLiteralTypes2.ts, 56, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 51, 38)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes2.ts, 57, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 59, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f10(x: YesNo) { +>f10 : Symbol(f10, Decl(enumLiteralTypes2.ts, 61, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 63, 13)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) + + switch (x) { +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 63, 13)) + + case Choice.Yes: return "true"; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + + case Choice.No: return "false"; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + } +} + +function f11(x: YesNo) { +>f11 : Symbol(f11, Decl(enumLiteralTypes2.ts, 68, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 70, 13)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) + + switch (x) { +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 70, 13)) + + case Choice.Yes: return "true"; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + + case Choice.No: return "false"; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes2.ts, 57, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 70, 13)) +} + +function f12(x: UnknownYesNo) { +>f12 : Symbol(f12, Decl(enumLiteralTypes2.ts, 76, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 78, 13)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) + + if (x) { +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 78, 13)) + + x; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 78, 13)) + } + else { + x; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 78, 13)) + } +} + +function f13(x: UnknownYesNo) { +>f13 : Symbol(f13, Decl(enumLiteralTypes2.ts, 85, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 87, 13)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) + + if (x === Choice.Yes) { +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 87, 13)) +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + + x; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 87, 13)) + } + else { + x; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 87, 13)) + } +} + +type Item = +>Item : Symbol(Item, Decl(enumLiteralTypes2.ts, 94, 1)) + + { kind: Choice.Yes, a: string } | +>kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) + + { kind: Choice.No, b: string }; +>kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 98, 5)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(enumLiteralTypes2.ts, 98, 35)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 100, 13)) +>Item : Symbol(Item, Decl(enumLiteralTypes2.ts, 94, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5), Decl(enumLiteralTypes2.ts, 98, 5)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 100, 13)) +>kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5), Decl(enumLiteralTypes2.ts, 98, 5)) + + case Choice.Yes: return x.a; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>x.a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 100, 13)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) + + case Choice.No: return x.b; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>x.b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 100, 13)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(enumLiteralTypes2.ts, 105, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +>Item : Symbol(Item, Decl(enumLiteralTypes2.ts, 94, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5), Decl(enumLiteralTypes2.ts, 98, 5)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +>kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5), Decl(enumLiteralTypes2.ts, 98, 5)) + + case Choice.Yes: return x.a; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>x.a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) + + case Choice.No: return x.b; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>x.b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes2.ts, 57, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +} diff --git a/tests/baselines/reference/enumLiteralTypes2.types b/tests/baselines/reference/enumLiteralTypes2.types new file mode 100644 index 00000000000..aab06c82fc4 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes2.types @@ -0,0 +1,450 @@ +=== tests/cases/conformance/types/literal/enumLiteralTypes2.ts === + +const enum Choice { Unknown, Yes, No }; +>Choice : Choice +>Unknown : Choice +>Yes : Choice +>No : Choice + +type YesNo = Choice.Yes | Choice.No; +>YesNo : Choice.Yes | Choice.No +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + +type NoYes = Choice.No | Choice.Yes; +>NoYes : Choice.No | Choice.Yes +>Choice : any +>No : Choice.No +>Choice : any +>Yes : Choice.Yes + +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>Choice : any +>Unknown : Choice.Unknown +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + +function f1() { +>f1 : () => void + + var a: YesNo; +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + var a: NoYes; +>a : Choice.Yes | Choice.No +>NoYes : Choice.No | Choice.Yes + + var a: Choice.Yes | Choice.No; +>a : Choice.Yes | Choice.No +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + + var a: Choice.No | Choice.Yes; +>a : Choice.Yes | Choice.No +>Choice : any +>No : Choice.No +>Choice : any +>Yes : Choice.Yes +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { +>f2 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>c : Choice +>Choice : Choice + + b = a; +>b = a : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>a : Choice.Yes | Choice.No + + c = a; +>c = a : Choice.Yes | Choice.No +>c : Choice +>a : Choice.Yes | Choice.No + + c = b; +>c = b : Choice.Yes | Choice.No +>c : Choice +>b : Choice.Yes | Choice.No +} + +function f3(a: Choice.Yes, b: UnknownYesNo) { +>f3 : (a: Choice.Yes, b: Choice.Unknown | Choice.Yes | Choice.No) => void +>a : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + var x = a + b; +>x : number +>a + b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a - b; +>x : number +>a - b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a * b; +>x : number +>a * b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a / b; +>x : number +>a / b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a % b; +>x : number +>a % b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a | b; +>x : number +>a | b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a & b; +>x : number +>a & b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a ^ b; +>x : number +>a ^ b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = -b; +>x : number +>-b : number +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = ~b; +>x : number +>~b : number +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a == b; +>y : boolean +>a == b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a != b; +>y : boolean +>a != b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a === b; +>y : boolean +>a === b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a !== b; +>y : boolean +>a !== b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a > b; +>y : boolean +>a > b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a < b; +>y : boolean +>a < b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a >= b; +>y : boolean +>a >= b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a <= b; +>y : boolean +>a <= b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = !b; +>y : boolean +>!b : boolean +>b : Choice.Unknown | Choice.Yes | Choice.No +} + +function f4(a: Choice.Yes, b: UnknownYesNo) { +>f4 : (a: Choice.Yes, b: Choice.Unknown | Choice.Yes | Choice.No) => void +>a : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + a++; +>a++ : number +>a : Choice.Yes + + b++; +>b++ : number +>b : Choice.Unknown | Choice.Yes | Choice.No +} + +declare function g(x: Choice.Yes): string; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice.Yes +>Choice : any +>Yes : Choice.Yes + +declare function g(x: Choice.No): boolean; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice.No +>Choice : any +>No : Choice.No + +declare function g(x: Choice): number; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice +>Choice : Choice + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { +>f5 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>c : Choice +>Choice : Choice + + var z1 = g(Choice.Yes); +>z1 : string +>g(Choice.Yes) : string +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes + + var z2 = g(Choice.No); +>z2 : boolean +>g(Choice.No) : boolean +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No + + var z3 = g(a); +>z3 : number +>g(a) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>a : Choice.Yes | Choice.No + + var z4 = g(b); +>z4 : number +>g(b) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>b : Choice.Unknown | Choice.Yes | Choice.No + + var z5 = g(c); +>z5 : number +>g(c) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>c : Choice +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +function f10(x: YesNo) { +>f10 : (x: Choice.Yes | Choice.No) => string +>x : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + switch (x) { +>x : Choice.Yes | Choice.No + + case Choice.Yes: return "true"; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>"true" : string + + case Choice.No: return "false"; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>"false" : string + } +} + +function f11(x: YesNo) { +>f11 : (x: Choice.Yes | Choice.No) => string +>x : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + switch (x) { +>x : Choice.Yes | Choice.No + + case Choice.Yes: return "true"; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>"true" : string + + case Choice.No: return "false"; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>"false" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: UnknownYesNo) { +>f12 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void +>x : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + if (x) { +>x : Choice.Unknown | Choice.Yes | Choice.No + + x; +>x : Choice.Yes | Choice.No + } + else { + x; +>x : Choice.Unknown + } +} + +function f13(x: UnknownYesNo) { +>f13 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void +>x : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + if (x === Choice.Yes) { +>x === Choice.Yes : boolean +>x : Choice.Unknown | Choice.Yes | Choice.No +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes + + x; +>x : Choice.Yes + } + else { + x; +>x : Choice.Unknown | Choice.No + } +} + +type Item = +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + { kind: Choice.Yes, a: string } | +>kind : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>a : string + + { kind: Choice.No, b: string }; +>kind : Choice.No +>Choice : any +>No : Choice.No +>b : string + +function f20(x: Item) { +>f20 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + switch (x.kind) { +>x.kind : Choice.Yes | Choice.No +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>kind : Choice.Yes | Choice.No + + case Choice.Yes: return x.a; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>x.a : string +>x : { kind: Choice.Yes; a: string; } +>a : string + + case Choice.No: return x.b; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>x.b : string +>x : { kind: Choice.No; b: string; } +>b : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + switch (x.kind) { +>x.kind : Choice.Yes | Choice.No +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>kind : Choice.Yes | Choice.No + + case Choice.Yes: return x.a; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>x.a : string +>x : { kind: Choice.Yes; a: string; } +>a : string + + case Choice.No: return x.b; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>x.b : string +>x : { kind: Choice.No; b: string; } +>b : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/enumLiteralTypes3.errors.txt b/tests/baselines/reference/enumLiteralTypes3.errors.txt new file mode 100644 index 00000000000..2f3ea5ada24 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes3.errors.txt @@ -0,0 +1,173 @@ +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(10,5): error TS2322: Type 'Yes | No' is not assignable to type 'Yes'. + Type 'No' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes'. + Type 'Unknown' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(12,5): error TS2322: Type 'Choice' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(18,5): error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes | No'. + Type 'Unknown' is not assignable to type 'Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(19,5): error TS2322: Type 'Choice' is not assignable to type 'Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(26,5): error TS2322: Type 'Choice' is not assignable to type 'Unknown | Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(37,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(39,5): error TS2322: Type 'No' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(40,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(52,5): error TS2365: Operator '===' cannot be applied to types 'Yes' and 'Unknown'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(54,5): error TS2365: Operator '===' cannot be applied to types 'Yes' and 'No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(55,5): error TS2365: Operator '===' cannot be applied to types 'Yes | No' and 'Unknown'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(87,14): error TS2678: Type 'Unknown' is not comparable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(89,14): error TS2678: Type 'No' is not comparable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: Type 'Unknown' is not comparable to type 'Yes | No'. + + +==== tests/cases/conformance/types/literal/enumLiteralTypes3.ts (15 errors) ==== + const enum Choice { Unknown, Yes, No }; + + type Yes = Choice.Yes; + type YesNo = Choice.Yes | Choice.No; + type NoYes = Choice.No | Choice.Yes; + type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + + function f1(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = a; + a = b; + ~ +!!! error TS2322: Type 'Yes | No' is not assignable to type 'Yes'. +!!! error TS2322: Type 'No' is not assignable to type 'Yes'. + a = c; + ~ +!!! error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes'. +!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes'. + a = d; + ~ +!!! error TS2322: Type 'Choice' is not assignable to type 'Yes'. + } + + function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + b = a; + b = b; + b = c; + ~ +!!! error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes | No'. +!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. + b = d; + ~ +!!! error TS2322: Type 'Choice' is not assignable to type 'Yes | No'. + } + + function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + c = a; + c = b; + c = c; + c = d; + ~ +!!! error TS2322: Type 'Choice' is not assignable to type 'Unknown | Yes | No'. + } + + function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + d = a; + d = b; + d = c; + d = d; + } + + function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = Choice.Unknown; + ~ +!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes'. + a = Choice.Yes; + a = Choice.No; + ~ +!!! error TS2322: Type 'No' is not assignable to type 'Yes'. + b = Choice.Unknown; + ~ +!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. + b = Choice.Yes; + b = Choice.No; + c = Choice.Unknown; + c = Choice.Yes; + c = Choice.No; + d = Choice.Unknown; + d = Choice.Yes; + d = Choice.No; + } + + function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === Choice.Unknown; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'Yes' and 'Unknown'. + a === Choice.Yes; + a === Choice.No; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'Yes' and 'No'. + b === Choice.Unknown; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'Yes | No' and 'Unknown'. + b === Choice.Yes; + b === Choice.No; + c === Choice.Unknown; + c === Choice.Yes; + c === Choice.No; + d === Choice.Unknown; + d === Choice.Yes; + d === Choice.No; + } + + function f7(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; + } + + function f10(x: Yes): Yes { + switch (x) { + case Choice.Unknown: return x; + ~~~~~~~~~~~~~~ +!!! error TS2678: Type 'Unknown' is not comparable to type 'Yes'. + case Choice.Yes: return x; + case Choice.No: return x; + ~~~~~~~~~ +!!! error TS2678: Type 'No' is not comparable to type 'Yes'. + } + return x; + } + + function f11(x: YesNo): YesNo { + switch (x) { + case Choice.Unknown: return x; + ~~~~~~~~~~~~~~ +!!! error TS2678: Type 'Unknown' is not comparable to type 'Yes | No'. + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; + } + + function f12(x: UnknownYesNo): UnknownYesNo { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; + } + + function f13(x: Choice): Choice { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; + } \ No newline at end of file diff --git a/tests/baselines/reference/enumLiteralTypes3.js b/tests/baselines/reference/enumLiteralTypes3.js new file mode 100644 index 00000000000..7eb3d0a1705 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes3.js @@ -0,0 +1,225 @@ +//// [enumLiteralTypes3.ts] +const enum Choice { Unknown, Yes, No }; + +type Yes = Choice.Yes; +type YesNo = Choice.Yes | Choice.No; +type NoYes = Choice.No | Choice.Yes; +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + +function f1(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = a; + a = b; + a = c; + a = d; +} + +function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + b = a; + b = b; + b = c; + b = d; +} + +function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + c = a; + c = b; + c = c; + c = d; +} + +function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + d = a; + d = b; + d = c; + d = d; +} + +function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = Choice.Unknown; + a = Choice.Yes; + a = Choice.No; + b = Choice.Unknown; + b = Choice.Yes; + b = Choice.No; + c = Choice.Unknown; + c = Choice.Yes; + c = Choice.No; + d = Choice.Unknown; + d = Choice.Yes; + d = Choice.No; +} + +function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === Choice.Unknown; + a === Choice.Yes; + a === Choice.No; + b === Choice.Unknown; + b === Choice.Yes; + b === Choice.No; + c === Choice.Unknown; + c === Choice.Yes; + c === Choice.No; + d === Choice.Unknown; + d === Choice.Yes; + d === Choice.No; +} + +function f7(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} + +function f10(x: Yes): Yes { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +function f11(x: YesNo): YesNo { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +function f12(x: UnknownYesNo): UnknownYesNo { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +function f13(x: Choice): Choice { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +//// [enumLiteralTypes3.js] +; +function f1(a, b, c, d) { + a = a; + a = b; + a = c; + a = d; +} +function f2(a, b, c, d) { + b = a; + b = b; + b = c; + b = d; +} +function f3(a, b, c, d) { + c = a; + c = b; + c = c; + c = d; +} +function f4(a, b, c, d) { + d = a; + d = b; + d = c; + d = d; +} +function f5(a, b, c, d) { + a = 0 /* Unknown */; + a = 1 /* Yes */; + a = 2 /* No */; + b = 0 /* Unknown */; + b = 1 /* Yes */; + b = 2 /* No */; + c = 0 /* Unknown */; + c = 1 /* Yes */; + c = 2 /* No */; + d = 0 /* Unknown */; + d = 1 /* Yes */; + d = 2 /* No */; +} +function f6(a, b, c, d) { + a === 0 /* Unknown */; + a === 1 /* Yes */; + a === 2 /* No */; + b === 0 /* Unknown */; + b === 1 /* Yes */; + b === 2 /* No */; + c === 0 /* Unknown */; + c === 1 /* Yes */; + c === 2 /* No */; + d === 0 /* Unknown */; + d === 1 /* Yes */; + d === 2 /* No */; +} +function f7(a, b, c, d) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} +function f10(x) { + switch (x) { + case 0 /* Unknown */: return x; + case 1 /* Yes */: return x; + case 2 /* No */: return x; + } + return x; +} +function f11(x) { + switch (x) { + case 0 /* Unknown */: return x; + case 1 /* Yes */: return x; + case 2 /* No */: return x; + } + return x; +} +function f12(x) { + switch (x) { + case 0 /* Unknown */: return x; + case 1 /* Yes */: return x; + case 2 /* No */: return x; + } + return x; +} +function f13(x) { + switch (x) { + case 0 /* Unknown */: return x; + case 1 /* Yes */: return x; + case 2 /* No */: return x; + } + return x; +} diff --git a/tests/baselines/reference/literalTypes1.js b/tests/baselines/reference/literalTypes1.js new file mode 100644 index 00000000000..cf2923e250a --- /dev/null +++ b/tests/baselines/reference/literalTypes1.js @@ -0,0 +1,173 @@ +//// [literalTypes1.ts] + +let zero: 0 = 0; +let one: 1 = 1; +let two: 2 = 2; +let oneOrTwo: 1 | 2 = <1 | 2>1; + +function f1(x: 0 | 1 | 2) { + switch (x) { + case zero: + x; + break; + case one: + x; + break; + case two: + x; + break; + default: + x; + } +} + +function f2(x: 0 | 1 | 2) { + switch (x) { + case zero: + x; + break; + case oneOrTwo: + x; + break; + default: + x; + } +} + +type Falsy = false | 0 | "" | null | undefined; + +function f3(x: Falsy) { + if (x) { + x; + } + else { + x; + } +} + +function f4(x: 0 | 1 | true | string) { + switch (x) { + case 0: + x; + break; + case 1: + x; + break; + case "abc": + case "def": + x; + break; + case null: + x; + break; + case undefined: + x; + break; + default: + x; + } +} + +function f5(x: string | number | boolean) { + switch (x) { + case "abc": + x; + break; + case 0: + case 1: + x; + break; + case true: + x; + break; + case "hello": + case 123: + x; + break; + default: + x; + } +} + +//// [literalTypes1.js] +var zero = 0; +var one = 1; +var two = 2; +var oneOrTwo = 1; +function f1(x) { + switch (x) { + case zero: + x; + break; + case one: + x; + break; + case two: + x; + break; + default: + x; + } +} +function f2(x) { + switch (x) { + case zero: + x; + break; + case oneOrTwo: + x; + break; + default: + x; + } +} +function f3(x) { + if (x) { + x; + } + else { + x; + } +} +function f4(x) { + switch (x) { + case 0: + x; + break; + case 1: + x; + break; + case "abc": + case "def": + x; + break; + case null: + x; + break; + case undefined: + x; + break; + default: + x; + } +} +function f5(x) { + switch (x) { + case "abc": + x; + break; + case 0: + case 1: + x; + break; + case true: + x; + break; + case "hello": + case 123: + x; + break; + default: + x; + } +} diff --git a/tests/baselines/reference/literalTypes1.symbols b/tests/baselines/reference/literalTypes1.symbols new file mode 100644 index 00000000000..ea44ab51acc --- /dev/null +++ b/tests/baselines/reference/literalTypes1.symbols @@ -0,0 +1,170 @@ +=== tests/cases/conformance/types/literal/literalTypes1.ts === + +let zero: 0 = 0; +>zero : Symbol(zero, Decl(literalTypes1.ts, 1, 3)) + +let one: 1 = 1; +>one : Symbol(one, Decl(literalTypes1.ts, 2, 3)) + +let two: 2 = 2; +>two : Symbol(two, Decl(literalTypes1.ts, 3, 3)) + +let oneOrTwo: 1 | 2 = <1 | 2>1; +>oneOrTwo : Symbol(oneOrTwo, Decl(literalTypes1.ts, 4, 3)) + +function f1(x: 0 | 1 | 2) { +>f1 : Symbol(f1, Decl(literalTypes1.ts, 4, 31)) +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + switch (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + case zero: +>zero : Symbol(zero, Decl(literalTypes1.ts, 1, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + break; + case one: +>one : Symbol(one, Decl(literalTypes1.ts, 2, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + break; + case two: +>two : Symbol(two, Decl(literalTypes1.ts, 3, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + break; + default: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + } +} + +function f2(x: 0 | 1 | 2) { +>f2 : Symbol(f2, Decl(literalTypes1.ts, 20, 1)) +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + + switch (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + + case zero: +>zero : Symbol(zero, Decl(literalTypes1.ts, 1, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + + break; + case oneOrTwo: +>oneOrTwo : Symbol(oneOrTwo, Decl(literalTypes1.ts, 4, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + + break; + default: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + } +} + +type Falsy = false | 0 | "" | null | undefined; +>Falsy : Symbol(Falsy, Decl(literalTypes1.ts, 33, 1)) + +function f3(x: Falsy) { +>f3 : Symbol(f3, Decl(literalTypes1.ts, 35, 47)) +>x : Symbol(x, Decl(literalTypes1.ts, 37, 12)) +>Falsy : Symbol(Falsy, Decl(literalTypes1.ts, 33, 1)) + + if (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 37, 12)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 37, 12)) + } + else { + x; +>x : Symbol(x, Decl(literalTypes1.ts, 37, 12)) + } +} + +function f4(x: 0 | 1 | true | string) { +>f4 : Symbol(f4, Decl(literalTypes1.ts, 44, 1)) +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + switch (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + case 0: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + case 1: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + case "abc": + case "def": + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + case null: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + case undefined: +>undefined : Symbol(undefined) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + default: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + } +} + +function f5(x: string | number | boolean) { +>f5 : Symbol(f5, Decl(literalTypes1.ts, 67, 1)) +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + switch (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + case "abc": + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + break; + case 0: + case 1: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + break; + case true: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + break; + case "hello": + case 123: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + break; + default: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + } +} diff --git a/tests/baselines/reference/literalTypes1.types b/tests/baselines/reference/literalTypes1.types new file mode 100644 index 00000000000..1428ce601a0 --- /dev/null +++ b/tests/baselines/reference/literalTypes1.types @@ -0,0 +1,200 @@ +=== tests/cases/conformance/types/literal/literalTypes1.ts === + +let zero: 0 = 0; +>zero : 0 +>0 : 0 + +let one: 1 = 1; +>one : 1 +>1 : 1 + +let two: 2 = 2; +>two : 2 +>2 : 2 + +let oneOrTwo: 1 | 2 = <1 | 2>1; +>oneOrTwo : 1 | 2 +><1 | 2>1 : 1 | 2 +>1 : 1 + +function f1(x: 0 | 1 | 2) { +>f1 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case zero: +>zero : 0 + + x; +>x : 0 + + break; + case one: +>one : 1 + + x; +>x : 1 + + break; + case two: +>two : 2 + + x; +>x : 2 + + break; + default: + x; +>x : never + } +} + +function f2(x: 0 | 1 | 2) { +>f2 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case zero: +>zero : 0 + + x; +>x : 0 | 1 | 2 + + break; + case oneOrTwo: +>oneOrTwo : 1 | 2 + + x; +>x : 0 | 1 | 2 + + break; + default: + x; +>x : 0 | 1 | 2 + } +} + +type Falsy = false | 0 | "" | null | undefined; +>Falsy : false | 0 | "" | null | undefined +>false : false +>null : null + +function f3(x: Falsy) { +>f3 : (x: false | 0 | "" | null | undefined) => void +>x : false | 0 | "" | null | undefined +>Falsy : false | 0 | "" | null | undefined + + if (x) { +>x : false | 0 | "" | null | undefined + + x; +>x : never + } + else { + x; +>x : false | 0 | "" | null | undefined + } +} + +function f4(x: 0 | 1 | true | string) { +>f4 : (x: 0 | 1 | true | string) => void +>x : 0 | 1 | true | string +>true : true + + switch (x) { +>x : 0 | 1 | true | string + + case 0: +>0 : 0 + + x; +>x : 0 + + break; + case 1: +>1 : 1 + + x; +>x : 1 + + break; + case "abc": +>"abc" : "abc" + + case "def": +>"def" : "def" + + x; +>x : string + + break; + case null: +>null : null + + x; +>x : never + + break; + case undefined: +>undefined : undefined + + x; +>x : never + + break; + default: + x; +>x : true | string + } +} + +function f5(x: string | number | boolean) { +>f5 : (x: string | number | boolean) => void +>x : string | number | boolean + + switch (x) { +>x : string | number | boolean + + case "abc": +>"abc" : "abc" + + x; +>x : string + + break; + case 0: +>0 : 0 + + case 1: +>1 : 1 + + x; +>x : number + + break; + case true: +>true : true + + x; +>x : boolean + + break; + case "hello": +>"hello" : "hello" + + case 123: +>123 : 123 + + x; +>x : string | number + + break; + default: + x; +>x : string | number | boolean + } +} diff --git a/tests/baselines/reference/numericLiteralTypes1.js b/tests/baselines/reference/numericLiteralTypes1.js new file mode 100644 index 00000000000..17c24d872ef --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes1.js @@ -0,0 +1,247 @@ +//// [numericLiteralTypes1.ts] +type A1 = 1; +type A2 = 1.0; +type A3 = 1e0; +type A4 = 10e-1; +type A5 = 1 | 1.0 | 1e0 | 10e-1; + +function f1() { + var a: A1 = 1; + var a: A2 = 1; + var a: A3 = 1; + var a: A4 = 1; + var a: A5 = 1; +} + +type B1 = -1 | 0 | 1; +type B2 = 1 | 0 | -1; +type B3 = 0 | -1 | 1; + +function f2() { + var b: B1 = -1; + var b: B2 = 0; + var b: B3 = 1; +} + +function f3(a: 1, b: 0 | 1 | 2) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: 1, b: 0 | 1 | 2) { + a++; + b++; +} + +declare function g(x: 0): string; +declare function g(x: 1): boolean; +declare function g(x: number): number; + +function f5(a: 1, b: 0 | 1 | 2) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +type Tag = 0 | 1 | 2; + +function f10(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} + +function f12(x: Tag) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: Tag) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} + +function f14(x: 0 | 1 | 2, y: string) { + var a = x && y; + var b = x || y; +} + +function f15(x: 0 | false, y: 1 | "one") { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} + +type Item = + { kind: 0, a: string } | + { kind: 1, b: string } | + { kind: 2, c: string }; + +function f20(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} + +function f21(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} + +//// [numericLiteralTypes1.js] +function f1() { + var a = 1; + var a = 1; + var a = 1; + var a = 1; + var a = 1; +} +function f2() { + var b = -1; + var b = 0; + var b = 1; +} +function f3(a, b) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} +function f4(a, b) { + a++; + b++; +} +function f5(a, b) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} +function f11(x) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} +function f14(x, y) { + var a = x && y; + var b = x || y; +} +function f15(x, y) { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} +function f20(x) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} +function f21(x) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/numericLiteralTypes1.symbols b/tests/baselines/reference/numericLiteralTypes1.symbols new file mode 100644 index 00000000000..87d2a15b291 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes1.symbols @@ -0,0 +1,413 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes1.ts === +type A1 = 1; +>A1 : Symbol(A1, Decl(numericLiteralTypes1.ts, 0, 0)) + +type A2 = 1.0; +>A2 : Symbol(A2, Decl(numericLiteralTypes1.ts, 0, 12)) + +type A3 = 1e0; +>A3 : Symbol(A3, Decl(numericLiteralTypes1.ts, 1, 14)) + +type A4 = 10e-1; +>A4 : Symbol(A4, Decl(numericLiteralTypes1.ts, 2, 14)) + +type A5 = 1 | 1.0 | 1e0 | 10e-1; +>A5 : Symbol(A5, Decl(numericLiteralTypes1.ts, 3, 16)) + +function f1() { +>f1 : Symbol(f1, Decl(numericLiteralTypes1.ts, 4, 32)) + + var a: A1 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A1 : Symbol(A1, Decl(numericLiteralTypes1.ts, 0, 0)) + + var a: A2 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A2 : Symbol(A2, Decl(numericLiteralTypes1.ts, 0, 12)) + + var a: A3 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A3 : Symbol(A3, Decl(numericLiteralTypes1.ts, 1, 14)) + + var a: A4 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A4 : Symbol(A4, Decl(numericLiteralTypes1.ts, 2, 14)) + + var a: A5 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A5 : Symbol(A5, Decl(numericLiteralTypes1.ts, 3, 16)) +} + +type B1 = -1 | 0 | 1; +>B1 : Symbol(B1, Decl(numericLiteralTypes1.ts, 12, 1)) + +type B2 = 1 | 0 | -1; +>B2 : Symbol(B2, Decl(numericLiteralTypes1.ts, 14, 21)) + +type B3 = 0 | -1 | 1; +>B3 : Symbol(B3, Decl(numericLiteralTypes1.ts, 15, 21)) + +function f2() { +>f2 : Symbol(f2, Decl(numericLiteralTypes1.ts, 16, 21)) + + var b: B1 = -1; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 19, 7), Decl(numericLiteralTypes1.ts, 20, 7), Decl(numericLiteralTypes1.ts, 21, 7)) +>B1 : Symbol(B1, Decl(numericLiteralTypes1.ts, 12, 1)) + + var b: B2 = 0; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 19, 7), Decl(numericLiteralTypes1.ts, 20, 7), Decl(numericLiteralTypes1.ts, 21, 7)) +>B2 : Symbol(B2, Decl(numericLiteralTypes1.ts, 14, 21)) + + var b: B3 = 1; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 19, 7), Decl(numericLiteralTypes1.ts, 20, 7), Decl(numericLiteralTypes1.ts, 21, 7)) +>B3 : Symbol(B3, Decl(numericLiteralTypes1.ts, 15, 21)) +} + +function f3(a: 1, b: 0 | 1 | 2) { +>f3 : Symbol(f3, Decl(numericLiteralTypes1.ts, 22, 1)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a + b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a - b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a * b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a / b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a % b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a | b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a & b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a ^ b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = -b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = ~b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a == b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a != b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a === b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a !== b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a > b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a < b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a >= b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a <= b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = !b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) +} + +function f4(a: 1, b: 0 | 1 | 2) { +>f4 : Symbol(f4, Decl(numericLiteralTypes1.ts, 44, 1)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 46, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 46, 17)) + + a++; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 46, 12)) + + b++; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 46, 17)) +} + +declare function g(x: 0): string; +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 51, 19)) + +declare function g(x: 1): boolean; +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 52, 19)) + +declare function g(x: number): number; +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 53, 19)) + +function f5(a: 1, b: 0 | 1 | 2) { +>f5 : Symbol(f5, Decl(numericLiteralTypes1.ts, 53, 38)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 55, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 55, 17)) + + var z1 = g(0); +>z1 : Symbol(z1, Decl(numericLiteralTypes1.ts, 56, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) + + var z2 = g(1); +>z2 : Symbol(z2, Decl(numericLiteralTypes1.ts, 57, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) + + var z3 = g(2); +>z3 : Symbol(z3, Decl(numericLiteralTypes1.ts, 58, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) + + var z4 = g(a); +>z4 : Symbol(z4, Decl(numericLiteralTypes1.ts, 59, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 55, 12)) + + var z5 = g(b); +>z5 : Symbol(z5, Decl(numericLiteralTypes1.ts, 60, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 55, 17)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes1.ts, 61, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 63, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +type Tag = 0 | 1 | 2; +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + +function f10(x: Tag) { +>f10 : Symbol(f10, Decl(numericLiteralTypes1.ts, 67, 21)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 69, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + + switch (x) { +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 69, 13)) + + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { +>f11 : Symbol(f11, Decl(numericLiteralTypes1.ts, 75, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 77, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + + switch (x) { +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 77, 13)) + + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes1.ts, 61, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 77, 13)) +} + +function f12(x: Tag) { +>f12 : Symbol(f12, Decl(numericLiteralTypes1.ts, 84, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 86, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + + if (x) { +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 86, 13)) + + x; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 86, 13)) + } + else { + x; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 86, 13)) + } +} + +function f13(x: Tag) { +>f13 : Symbol(f13, Decl(numericLiteralTypes1.ts, 93, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + + if (x === 0 || x === 2) { +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) + + x; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) + } + else { + x; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) + } +} + +function f14(x: 0 | 1 | 2, y: string) { +>f14 : Symbol(f14, Decl(numericLiteralTypes1.ts, 102, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 104, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 104, 26)) + + var a = x && y; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 105, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 104, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 104, 26)) + + var b = x || y; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 106, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 104, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 104, 26)) +} + +function f15(x: 0 | false, y: 1 | "one") { +>f15 : Symbol(f15, Decl(numericLiteralTypes1.ts, 107, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) + + var a = x && y; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 110, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) + + var b = y && x; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 111, 7)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) + + var c = x || y; +>c : Symbol(c, Decl(numericLiteralTypes1.ts, 112, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) + + var d = y || x; +>d : Symbol(d, Decl(numericLiteralTypes1.ts, 113, 7)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) + + var e = !x; +>e : Symbol(e, Decl(numericLiteralTypes1.ts, 114, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) + + var f = !y; +>f : Symbol(f, Decl(numericLiteralTypes1.ts, 115, 7)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) +} + +type Item = +>Item : Symbol(Item, Decl(numericLiteralTypes1.ts, 116, 1)) + + { kind: 0, a: string } | +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) + + { kind: 1, b: string } | +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 120, 5)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) + + { kind: 2, c: string }; +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 121, 5)) +>c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(numericLiteralTypes1.ts, 121, 27)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>Item : Symbol(Item, Decl(numericLiteralTypes1.ts, 116, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5), Decl(numericLiteralTypes1.ts, 120, 5), Decl(numericLiteralTypes1.ts, 121, 5)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5), Decl(numericLiteralTypes1.ts, 120, 5), Decl(numericLiteralTypes1.ts, 121, 5)) + + case 0: return x.a; +>x.a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) + + case 1: return x.b; +>x.b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) + + case 2: return x.c; +>x.c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(numericLiteralTypes1.ts, 129, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>Item : Symbol(Item, Decl(numericLiteralTypes1.ts, 116, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5), Decl(numericLiteralTypes1.ts, 120, 5), Decl(numericLiteralTypes1.ts, 121, 5)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5), Decl(numericLiteralTypes1.ts, 120, 5), Decl(numericLiteralTypes1.ts, 121, 5)) + + case 0: return x.a; +>x.a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) + + case 1: return x.b; +>x.b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) + + case 2: return x.c; +>x.c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes1.ts, 61, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +} diff --git a/tests/baselines/reference/numericLiteralTypes1.types b/tests/baselines/reference/numericLiteralTypes1.types new file mode 100644 index 00000000000..f5632c2fa71 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes1.types @@ -0,0 +1,497 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes1.ts === +type A1 = 1; +>A1 : 1 + +type A2 = 1.0; +>A2 : 1 + +type A3 = 1e0; +>A3 : 1 + +type A4 = 10e-1; +>A4 : 1 + +type A5 = 1 | 1.0 | 1e0 | 10e-1; +>A5 : 1 + +function f1() { +>f1 : () => void + + var a: A1 = 1; +>a : 1 +>A1 : 1 +>1 : 1 + + var a: A2 = 1; +>a : 1 +>A2 : 1 +>1 : 1 + + var a: A3 = 1; +>a : 1 +>A3 : 1 +>1 : 1 + + var a: A4 = 1; +>a : 1 +>A4 : 1 +>1 : 1 + + var a: A5 = 1; +>a : 1 +>A5 : 1 +>1 : 1 +} + +type B1 = -1 | 0 | 1; +>B1 : -1 | 0 | 1 +>-1 : -1 +>1 : number + +type B2 = 1 | 0 | -1; +>B2 : 1 | 0 | -1 +>-1 : -1 +>1 : number + +type B3 = 0 | -1 | 1; +>B3 : 0 | -1 | 1 +>-1 : -1 +>1 : number + +function f2() { +>f2 : () => void + + var b: B1 = -1; +>b : -1 | 0 | 1 +>B1 : -1 | 0 | 1 +>-1 : -1 +>1 : number + + var b: B2 = 0; +>b : -1 | 0 | 1 +>B2 : 1 | 0 | -1 +>0 : 0 + + var b: B3 = 1; +>b : -1 | 0 | 1 +>B3 : 0 | -1 | 1 +>1 : 1 +} + +function f3(a: 1, b: 0 | 1 | 2) { +>f3 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + var x = a + b; +>x : number +>a + b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a - b; +>x : number +>a - b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a * b; +>x : number +>a * b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a / b; +>x : number +>a / b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a % b; +>x : number +>a % b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a | b; +>x : number +>a | b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a & b; +>x : number +>a & b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a ^ b; +>x : number +>a ^ b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = -b; +>x : number +>-b : number +>b : 0 | 1 | 2 + + var x = ~b; +>x : number +>~b : number +>b : 0 | 1 | 2 + + var y = a == b; +>y : boolean +>a == b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a != b; +>y : boolean +>a != b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a === b; +>y : boolean +>a === b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a !== b; +>y : boolean +>a !== b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a > b; +>y : boolean +>a > b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a < b; +>y : boolean +>a < b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a >= b; +>y : boolean +>a >= b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a <= b; +>y : boolean +>a <= b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = !b; +>y : boolean +>!b : boolean +>b : 0 | 1 | 2 +} + +function f4(a: 1, b: 0 | 1 | 2) { +>f4 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + a++; +>a++ : number +>a : 1 + + b++; +>b++ : number +>b : 0 | 1 | 2 +} + +declare function g(x: 0): string; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : 0 + +declare function g(x: 1): boolean; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : 1 + +declare function g(x: number): number; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : number + +function f5(a: 1, b: 0 | 1 | 2) { +>f5 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + var z1 = g(0); +>z1 : string +>g(0) : string +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>0 : 0 + + var z2 = g(1); +>z2 : boolean +>g(1) : boolean +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>1 : 1 + + var z3 = g(2); +>z3 : number +>g(2) : number +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>2 : number + + var z4 = g(a); +>z4 : boolean +>g(a) : boolean +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>a : 1 + + var z5 = g(b); +>z5 : number +>g(b) : number +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>b : 0 | 1 | 2 +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +type Tag = 0 | 1 | 2; +>Tag : 0 | 1 | 2 + +function f10(x: Tag) { +>f10 : (x: 0 | 1 | 2) => string +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case 0: return "a"; +>0 : 0 +>"a" : string + + case 1: return "b"; +>1 : 1 +>"b" : string + + case 2: return "c"; +>2 : 2 +>"c" : string + } +} + +function f11(x: Tag) { +>f11 : (x: 0 | 1 | 2) => string +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case 0: return "a"; +>0 : 0 +>"a" : string + + case 1: return "b"; +>1 : 1 +>"b" : string + + case 2: return "c"; +>2 : 2 +>"c" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: Tag) { +>f12 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + if (x) { +>x : 0 | 1 | 2 + + x; +>x : 1 | 2 + } + else { + x; +>x : 0 | 1 | 2 + } +} + +function f13(x: Tag) { +>f13 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + if (x === 0 || x === 2) { +>x === 0 || x === 2 : boolean +>x === 0 : boolean +>x : 0 | 1 | 2 +>0 : 0 +>x === 2 : boolean +>x : 1 | 2 +>2 : 2 + + x; +>x : 0 | 2 + } + else { + x; +>x : 1 + } +} + +function f14(x: 0 | 1 | 2, y: string) { +>f14 : (x: 0 | 1 | 2, y: string) => void +>x : 0 | 1 | 2 +>y : string + + var a = x && y; +>a : string +>x && y : string +>x : 0 | 1 | 2 +>y : string + + var b = x || y; +>b : 1 | 2 | string +>x || y : 1 | 2 | string +>x : 0 | 1 | 2 +>y : string +} + +function f15(x: 0 | false, y: 1 | "one") { +>f15 : (x: 0 | false, y: 1 | "one") => void +>x : 0 | false +>false : false +>y : 1 | "one" + + var a = x && y; +>a : 0 | false +>x && y : 0 | false +>x : 0 | false +>y : 1 | "one" + + var b = y && x; +>b : 0 | false +>y && x : 0 | false +>y : 1 | "one" +>x : 0 | false + + var c = x || y; +>c : 1 | "one" +>x || y : 1 | "one" +>x : 0 | false +>y : 1 | "one" + + var d = y || x; +>d : 1 | "one" | 0 | false +>y || x : 1 | "one" | 0 | false +>y : 1 | "one" +>x : 0 | false + + var e = !x; +>e : true +>!x : true +>x : 0 | false + + var f = !y; +>f : boolean +>!y : boolean +>y : 1 | "one" +} + +type Item = +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + { kind: 0, a: string } | +>kind : 0 +>a : string + + { kind: 1, b: string } | +>kind : 1 +>b : string + + { kind: 2, c: string }; +>kind : 2 +>c : string + +function f20(x: Item) { +>f20 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + switch (x.kind) { +>x.kind : 0 | 1 | 2 +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>kind : 0 | 1 | 2 + + case 0: return x.a; +>0 : 0 +>x.a : string +>x : { kind: 0; a: string; } +>a : string + + case 1: return x.b; +>1 : 1 +>x.b : string +>x : { kind: 1; b: string; } +>b : string + + case 2: return x.c; +>2 : 2 +>x.c : string +>x : { kind: 2; c: string; } +>c : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + switch (x.kind) { +>x.kind : 0 | 1 | 2 +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>kind : 0 | 1 | 2 + + case 0: return x.a; +>0 : 0 +>x.a : string +>x : { kind: 0; a: string; } +>a : string + + case 1: return x.b; +>1 : 1 +>x.b : string +>x : { kind: 1; b: string; } +>b : string + + case 2: return x.c; +>2 : 2 +>x.c : string +>x : { kind: 2; c: string; } +>c : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/numericLiteralTypes2.js b/tests/baselines/reference/numericLiteralTypes2.js new file mode 100644 index 00000000000..ea82d00832c --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes2.js @@ -0,0 +1,248 @@ +//// [numericLiteralTypes2.ts] + +type A1 = 1; +type A2 = 1.0; +type A3 = 1e0; +type A4 = 10e-1; +type A5 = 1 | 1.0 | 1e0 | 10e-1; + +function f1() { + var a: A1 = 1; + var a: A2 = 1; + var a: A3 = 1; + var a: A4 = 1; + var a: A5 = 1; +} + +type B1 = -1 | 0 | 1; +type B2 = 1 | 0 | -1; +type B3 = 0 | -1 | 1; + +function f2() { + var b: B1 = -1; + var b: B2 = 0; + var b: B3 = 1; +} + +function f3(a: 1, b: 0 | 1 | 2) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: 1, b: 0 | 1 | 2) { + a++; + b++; +} + +declare function g(x: 0): string; +declare function g(x: 1): boolean; +declare function g(x: number): number; + +function f5(a: 1, b: 0 | 1 | 2) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +type Tag = 0 | 1 | 2; + +function f10(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} + +function f12(x: Tag) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: Tag) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} + +function f14(x: 0 | 1 | 2, y: string) { + var a = x && y; + var b = x || y; +} + +function f15(x: 0 | false, y: 1 | "one") { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} + +type Item = + { kind: 0, a: string } | + { kind: 1, b: string } | + { kind: 2, c: string }; + +function f20(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} + +function f21(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} + +//// [numericLiteralTypes2.js] +function f1() { + var a = 1; + var a = 1; + var a = 1; + var a = 1; + var a = 1; +} +function f2() { + var b = -1; + var b = 0; + var b = 1; +} +function f3(a, b) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} +function f4(a, b) { + a++; + b++; +} +function f5(a, b) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} +function f11(x) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} +function f14(x, y) { + var a = x && y; + var b = x || y; +} +function f15(x, y) { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} +function f20(x) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} +function f21(x) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/numericLiteralTypes2.symbols b/tests/baselines/reference/numericLiteralTypes2.symbols new file mode 100644 index 00000000000..f0dbbda502e --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes2.symbols @@ -0,0 +1,414 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes2.ts === + +type A1 = 1; +>A1 : Symbol(A1, Decl(numericLiteralTypes2.ts, 0, 0)) + +type A2 = 1.0; +>A2 : Symbol(A2, Decl(numericLiteralTypes2.ts, 1, 12)) + +type A3 = 1e0; +>A3 : Symbol(A3, Decl(numericLiteralTypes2.ts, 2, 14)) + +type A4 = 10e-1; +>A4 : Symbol(A4, Decl(numericLiteralTypes2.ts, 3, 14)) + +type A5 = 1 | 1.0 | 1e0 | 10e-1; +>A5 : Symbol(A5, Decl(numericLiteralTypes2.ts, 4, 16)) + +function f1() { +>f1 : Symbol(f1, Decl(numericLiteralTypes2.ts, 5, 32)) + + var a: A1 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A1 : Symbol(A1, Decl(numericLiteralTypes2.ts, 0, 0)) + + var a: A2 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A2 : Symbol(A2, Decl(numericLiteralTypes2.ts, 1, 12)) + + var a: A3 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A3 : Symbol(A3, Decl(numericLiteralTypes2.ts, 2, 14)) + + var a: A4 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A4 : Symbol(A4, Decl(numericLiteralTypes2.ts, 3, 14)) + + var a: A5 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A5 : Symbol(A5, Decl(numericLiteralTypes2.ts, 4, 16)) +} + +type B1 = -1 | 0 | 1; +>B1 : Symbol(B1, Decl(numericLiteralTypes2.ts, 13, 1)) + +type B2 = 1 | 0 | -1; +>B2 : Symbol(B2, Decl(numericLiteralTypes2.ts, 15, 21)) + +type B3 = 0 | -1 | 1; +>B3 : Symbol(B3, Decl(numericLiteralTypes2.ts, 16, 21)) + +function f2() { +>f2 : Symbol(f2, Decl(numericLiteralTypes2.ts, 17, 21)) + + var b: B1 = -1; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 20, 7), Decl(numericLiteralTypes2.ts, 21, 7), Decl(numericLiteralTypes2.ts, 22, 7)) +>B1 : Symbol(B1, Decl(numericLiteralTypes2.ts, 13, 1)) + + var b: B2 = 0; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 20, 7), Decl(numericLiteralTypes2.ts, 21, 7), Decl(numericLiteralTypes2.ts, 22, 7)) +>B2 : Symbol(B2, Decl(numericLiteralTypes2.ts, 15, 21)) + + var b: B3 = 1; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 20, 7), Decl(numericLiteralTypes2.ts, 21, 7), Decl(numericLiteralTypes2.ts, 22, 7)) +>B3 : Symbol(B3, Decl(numericLiteralTypes2.ts, 16, 21)) +} + +function f3(a: 1, b: 0 | 1 | 2) { +>f3 : Symbol(f3, Decl(numericLiteralTypes2.ts, 23, 1)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a + b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a - b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a * b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a / b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a % b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a | b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a & b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a ^ b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = -b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = ~b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a == b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a != b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a === b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a !== b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a > b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a < b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a >= b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a <= b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = !b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) +} + +function f4(a: 1, b: 0 | 1 | 2) { +>f4 : Symbol(f4, Decl(numericLiteralTypes2.ts, 45, 1)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 47, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 47, 17)) + + a++; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 47, 12)) + + b++; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 47, 17)) +} + +declare function g(x: 0): string; +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 52, 19)) + +declare function g(x: 1): boolean; +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 53, 19)) + +declare function g(x: number): number; +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 54, 19)) + +function f5(a: 1, b: 0 | 1 | 2) { +>f5 : Symbol(f5, Decl(numericLiteralTypes2.ts, 54, 38)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 56, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 56, 17)) + + var z1 = g(0); +>z1 : Symbol(z1, Decl(numericLiteralTypes2.ts, 57, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) + + var z2 = g(1); +>z2 : Symbol(z2, Decl(numericLiteralTypes2.ts, 58, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) + + var z3 = g(2); +>z3 : Symbol(z3, Decl(numericLiteralTypes2.ts, 59, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) + + var z4 = g(a); +>z4 : Symbol(z4, Decl(numericLiteralTypes2.ts, 60, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 56, 12)) + + var z5 = g(b); +>z5 : Symbol(z5, Decl(numericLiteralTypes2.ts, 61, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 56, 17)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes2.ts, 62, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 64, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +type Tag = 0 | 1 | 2; +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + +function f10(x: Tag) { +>f10 : Symbol(f10, Decl(numericLiteralTypes2.ts, 68, 21)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 70, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + + switch (x) { +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 70, 13)) + + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { +>f11 : Symbol(f11, Decl(numericLiteralTypes2.ts, 76, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 78, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + + switch (x) { +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 78, 13)) + + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes2.ts, 62, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 78, 13)) +} + +function f12(x: Tag) { +>f12 : Symbol(f12, Decl(numericLiteralTypes2.ts, 85, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 87, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + + if (x) { +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 87, 13)) + + x; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 87, 13)) + } + else { + x; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 87, 13)) + } +} + +function f13(x: Tag) { +>f13 : Symbol(f13, Decl(numericLiteralTypes2.ts, 94, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + + if (x === 0 || x === 2) { +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) + + x; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) + } + else { + x; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) + } +} + +function f14(x: 0 | 1 | 2, y: string) { +>f14 : Symbol(f14, Decl(numericLiteralTypes2.ts, 103, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 105, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 105, 26)) + + var a = x && y; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 106, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 105, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 105, 26)) + + var b = x || y; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 107, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 105, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 105, 26)) +} + +function f15(x: 0 | false, y: 1 | "one") { +>f15 : Symbol(f15, Decl(numericLiteralTypes2.ts, 108, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) + + var a = x && y; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 111, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) + + var b = y && x; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 112, 7)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) + + var c = x || y; +>c : Symbol(c, Decl(numericLiteralTypes2.ts, 113, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) + + var d = y || x; +>d : Symbol(d, Decl(numericLiteralTypes2.ts, 114, 7)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) + + var e = !x; +>e : Symbol(e, Decl(numericLiteralTypes2.ts, 115, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) + + var f = !y; +>f : Symbol(f, Decl(numericLiteralTypes2.ts, 116, 7)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) +} + +type Item = +>Item : Symbol(Item, Decl(numericLiteralTypes2.ts, 117, 1)) + + { kind: 0, a: string } | +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) + + { kind: 1, b: string } | +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 121, 5)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) + + { kind: 2, c: string }; +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 122, 5)) +>c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(numericLiteralTypes2.ts, 122, 27)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>Item : Symbol(Item, Decl(numericLiteralTypes2.ts, 117, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5), Decl(numericLiteralTypes2.ts, 121, 5), Decl(numericLiteralTypes2.ts, 122, 5)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5), Decl(numericLiteralTypes2.ts, 121, 5), Decl(numericLiteralTypes2.ts, 122, 5)) + + case 0: return x.a; +>x.a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) + + case 1: return x.b; +>x.b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) + + case 2: return x.c; +>x.c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(numericLiteralTypes2.ts, 130, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>Item : Symbol(Item, Decl(numericLiteralTypes2.ts, 117, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5), Decl(numericLiteralTypes2.ts, 121, 5), Decl(numericLiteralTypes2.ts, 122, 5)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5), Decl(numericLiteralTypes2.ts, 121, 5), Decl(numericLiteralTypes2.ts, 122, 5)) + + case 0: return x.a; +>x.a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) + + case 1: return x.b; +>x.b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) + + case 2: return x.c; +>x.c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes2.ts, 62, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +} diff --git a/tests/baselines/reference/numericLiteralTypes2.types b/tests/baselines/reference/numericLiteralTypes2.types new file mode 100644 index 00000000000..36c5026ba11 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes2.types @@ -0,0 +1,498 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes2.ts === + +type A1 = 1; +>A1 : 1 + +type A2 = 1.0; +>A2 : 1 + +type A3 = 1e0; +>A3 : 1 + +type A4 = 10e-1; +>A4 : 1 + +type A5 = 1 | 1.0 | 1e0 | 10e-1; +>A5 : 1 + +function f1() { +>f1 : () => void + + var a: A1 = 1; +>a : 1 +>A1 : 1 +>1 : 1 + + var a: A2 = 1; +>a : 1 +>A2 : 1 +>1 : 1 + + var a: A3 = 1; +>a : 1 +>A3 : 1 +>1 : 1 + + var a: A4 = 1; +>a : 1 +>A4 : 1 +>1 : 1 + + var a: A5 = 1; +>a : 1 +>A5 : 1 +>1 : 1 +} + +type B1 = -1 | 0 | 1; +>B1 : -1 | 0 | 1 +>-1 : -1 +>1 : number + +type B2 = 1 | 0 | -1; +>B2 : 1 | 0 | -1 +>-1 : -1 +>1 : number + +type B3 = 0 | -1 | 1; +>B3 : 0 | -1 | 1 +>-1 : -1 +>1 : number + +function f2() { +>f2 : () => void + + var b: B1 = -1; +>b : -1 | 0 | 1 +>B1 : -1 | 0 | 1 +>-1 : -1 +>1 : number + + var b: B2 = 0; +>b : -1 | 0 | 1 +>B2 : 1 | 0 | -1 +>0 : 0 + + var b: B3 = 1; +>b : -1 | 0 | 1 +>B3 : 0 | -1 | 1 +>1 : 1 +} + +function f3(a: 1, b: 0 | 1 | 2) { +>f3 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + var x = a + b; +>x : number +>a + b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a - b; +>x : number +>a - b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a * b; +>x : number +>a * b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a / b; +>x : number +>a / b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a % b; +>x : number +>a % b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a | b; +>x : number +>a | b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a & b; +>x : number +>a & b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a ^ b; +>x : number +>a ^ b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = -b; +>x : number +>-b : number +>b : 0 | 1 | 2 + + var x = ~b; +>x : number +>~b : number +>b : 0 | 1 | 2 + + var y = a == b; +>y : boolean +>a == b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a != b; +>y : boolean +>a != b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a === b; +>y : boolean +>a === b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a !== b; +>y : boolean +>a !== b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a > b; +>y : boolean +>a > b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a < b; +>y : boolean +>a < b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a >= b; +>y : boolean +>a >= b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a <= b; +>y : boolean +>a <= b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = !b; +>y : boolean +>!b : boolean +>b : 0 | 1 | 2 +} + +function f4(a: 1, b: 0 | 1 | 2) { +>f4 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + a++; +>a++ : number +>a : 1 + + b++; +>b++ : number +>b : 0 | 1 | 2 +} + +declare function g(x: 0): string; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : 0 + +declare function g(x: 1): boolean; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : 1 + +declare function g(x: number): number; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : number + +function f5(a: 1, b: 0 | 1 | 2) { +>f5 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + var z1 = g(0); +>z1 : string +>g(0) : string +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>0 : 0 + + var z2 = g(1); +>z2 : boolean +>g(1) : boolean +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>1 : 1 + + var z3 = g(2); +>z3 : number +>g(2) : number +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>2 : number + + var z4 = g(a); +>z4 : boolean +>g(a) : boolean +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>a : 1 + + var z5 = g(b); +>z5 : number +>g(b) : number +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>b : 0 | 1 | 2 +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +type Tag = 0 | 1 | 2; +>Tag : 0 | 1 | 2 + +function f10(x: Tag) { +>f10 : (x: 0 | 1 | 2) => string +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case 0: return "a"; +>0 : 0 +>"a" : string + + case 1: return "b"; +>1 : 1 +>"b" : string + + case 2: return "c"; +>2 : 2 +>"c" : string + } +} + +function f11(x: Tag) { +>f11 : (x: 0 | 1 | 2) => string +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case 0: return "a"; +>0 : 0 +>"a" : string + + case 1: return "b"; +>1 : 1 +>"b" : string + + case 2: return "c"; +>2 : 2 +>"c" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: Tag) { +>f12 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + if (x) { +>x : 0 | 1 | 2 + + x; +>x : 1 | 2 + } + else { + x; +>x : 0 + } +} + +function f13(x: Tag) { +>f13 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + if (x === 0 || x === 2) { +>x === 0 || x === 2 : boolean +>x === 0 : boolean +>x : 0 | 1 | 2 +>0 : 0 +>x === 2 : boolean +>x : 1 | 2 +>2 : 2 + + x; +>x : 0 | 2 + } + else { + x; +>x : 1 + } +} + +function f14(x: 0 | 1 | 2, y: string) { +>f14 : (x: 0 | 1 | 2, y: string) => void +>x : 0 | 1 | 2 +>y : string + + var a = x && y; +>a : string | 0 +>x && y : string | 0 +>x : 0 | 1 | 2 +>y : string + + var b = x || y; +>b : 1 | 2 | string +>x || y : 1 | 2 | string +>x : 0 | 1 | 2 +>y : string +} + +function f15(x: 0 | false, y: 1 | "one") { +>f15 : (x: 0 | false, y: 1 | "one") => void +>x : 0 | false +>false : false +>y : 1 | "one" + + var a = x && y; +>a : 0 | false +>x && y : 0 | false +>x : 0 | false +>y : 1 | "one" + + var b = y && x; +>b : 0 | false +>y && x : 0 | false +>y : 1 | "one" +>x : 0 | false + + var c = x || y; +>c : 1 | "one" +>x || y : 1 | "one" +>x : 0 | false +>y : 1 | "one" + + var d = y || x; +>d : 1 | "one" +>y || x : 1 | "one" +>y : 1 | "one" +>x : 0 | false + + var e = !x; +>e : true +>!x : true +>x : 0 | false + + var f = !y; +>f : false +>!y : false +>y : 1 | "one" +} + +type Item = +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + { kind: 0, a: string } | +>kind : 0 +>a : string + + { kind: 1, b: string } | +>kind : 1 +>b : string + + { kind: 2, c: string }; +>kind : 2 +>c : string + +function f20(x: Item) { +>f20 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + switch (x.kind) { +>x.kind : 0 | 1 | 2 +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>kind : 0 | 1 | 2 + + case 0: return x.a; +>0 : 0 +>x.a : string +>x : { kind: 0; a: string; } +>a : string + + case 1: return x.b; +>1 : 1 +>x.b : string +>x : { kind: 1; b: string; } +>b : string + + case 2: return x.c; +>2 : 2 +>x.c : string +>x : { kind: 2; c: string; } +>c : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + switch (x.kind) { +>x.kind : 0 | 1 | 2 +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>kind : 0 | 1 | 2 + + case 0: return x.a; +>0 : 0 +>x.a : string +>x : { kind: 0; a: string; } +>a : string + + case 1: return x.b; +>1 : 1 +>x.b : string +>x : { kind: 1; b: string; } +>b : string + + case 2: return x.c; +>2 : 2 +>x.c : string +>x : { kind: 2; c: string; } +>c : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/numericLiteralTypes3.errors.txt b/tests/baselines/reference/numericLiteralTypes3.errors.txt new file mode 100644 index 00000000000..19a61bce786 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes3.errors.txt @@ -0,0 +1,203 @@ +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(8,5): error TS2322: Type '2 | 3' is not assignable to type '1'. + Type '2' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(9,5): error TS2322: Type '1 | 2 | 3' is not assignable to type '1'. + Type '2' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(10,5): error TS2322: Type '0 | 1 | 2' is not assignable to type '1'. + Type '0' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(14,5): error TS2322: Type '1' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(16,5): error TS2322: Type '1 | 2 | 3' is not assignable to type '2 | 3'. + Type '1' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(17,5): error TS2322: Type '0 | 1 | 2' is not assignable to type '2 | 3'. + Type '0' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(24,5): error TS2322: Type '0 | 1 | 2' is not assignable to type '1 | 2 | 3'. + Type '0' is not assignable to type '1 | 2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(29,5): error TS2322: Type '2 | 3' is not assignable to type '0 | 1 | 2'. + Type '3' is not assignable to type '0 | 1 | 2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(30,5): error TS2322: Type '1 | 2 | 3' is not assignable to type '0 | 1 | 2'. + Type '3' is not assignable to type '0 | 1 | 2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(35,5): error TS2322: Type '0' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(37,5): error TS2322: Type '2' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(38,5): error TS2322: Type '3' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(39,5): error TS2322: Type '0' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(40,5): error TS2322: Type '1' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(43,5): error TS2322: Type '0' is not assignable to type '1 | 2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(50,5): error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(54,5): error TS2365: Operator '===' cannot be applied to types '1' and '0'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(56,5): error TS2365: Operator '===' cannot be applied to types '1' and '2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(57,5): error TS2365: Operator '===' cannot be applied to types '1' and '3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(58,5): error TS2365: Operator '===' cannot be applied to types '2 | 3' and '0'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(59,5): error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(62,5): error TS2365: Operator '===' cannot be applied to types '1 | 2 | 3' and '0'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(69,5): error TS2365: Operator '===' cannot be applied to types '0 | 1 | 2' and '3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(74,5): error TS2365: Operator '===' cannot be applied to types '1' and '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(77,5): error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(94,14): error TS2678: Type '1' is not comparable to type '0 | 2 | 4'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(96,14): error TS2678: Type '3' is not comparable to type '0 | 2 | 4'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(98,14): error TS2678: Type '5' is not comparable to type '0 | 2 | 4'. + + +==== tests/cases/conformance/types/literal/numericLiteralTypes3.ts (28 errors) ==== + type A = 1; + type B = 2 | 3; + type C = 1 | 2 | 3; + type D = 0 | 1 | 2; + + function f1(a: A, b: B, c: C, d: D) { + a = a; + a = b; + ~ +!!! error TS2322: Type '2 | 3' is not assignable to type '1'. +!!! error TS2322: Type '2' is not assignable to type '1'. + a = c; + ~ +!!! error TS2322: Type '1 | 2 | 3' is not assignable to type '1'. +!!! error TS2322: Type '2' is not assignable to type '1'. + a = d; + ~ +!!! error TS2322: Type '0 | 1 | 2' is not assignable to type '1'. +!!! error TS2322: Type '0' is not assignable to type '1'. + } + + function f2(a: A, b: B, c: C, d: D) { + b = a; + ~ +!!! error TS2322: Type '1' is not assignable to type '2 | 3'. + b = b; + b = c; + ~ +!!! error TS2322: Type '1 | 2 | 3' is not assignable to type '2 | 3'. +!!! error TS2322: Type '1' is not assignable to type '2 | 3'. + b = d; + ~ +!!! error TS2322: Type '0 | 1 | 2' is not assignable to type '2 | 3'. +!!! error TS2322: Type '0' is not assignable to type '2 | 3'. + } + + function f3(a: A, b: B, c: C, d: D) { + c = a; + c = b; + c = c; + c = d; + ~ +!!! error TS2322: Type '0 | 1 | 2' is not assignable to type '1 | 2 | 3'. +!!! error TS2322: Type '0' is not assignable to type '1 | 2 | 3'. + } + + function f4(a: A, b: B, c: C, d: D) { + d = a; + d = b; + ~ +!!! error TS2322: Type '2 | 3' is not assignable to type '0 | 1 | 2'. +!!! error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. + d = c; + ~ +!!! error TS2322: Type '1 | 2 | 3' is not assignable to type '0 | 1 | 2'. +!!! error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. + d = d; + } + + function f5(a: A, b: B, c: C, d: D) { + a = 0; + ~ +!!! error TS2322: Type '0' is not assignable to type '1'. + a = 1; + a = 2; + ~ +!!! error TS2322: Type '2' is not assignable to type '1'. + a = 3; + ~ +!!! error TS2322: Type '3' is not assignable to type '1'. + b = 0; + ~ +!!! error TS2322: Type '0' is not assignable to type '2 | 3'. + b = 1; + ~ +!!! error TS2322: Type '1' is not assignable to type '2 | 3'. + b = 2; + b = 3; + c = 0; + ~ +!!! error TS2322: Type '0' is not assignable to type '1 | 2 | 3'. + c = 1; + c = 2; + c = 3; + d = 0; + d = 1; + d = 2; + d = 3; + ~ +!!! error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. + } + + function f6(a: A, b: B, c: C, d: D) { + a === 0; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1' and '0'. + a === 1; + a === 2; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1' and '2'. + a === 3; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1' and '3'. + b === 0; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '2 | 3' and '0'. + b === 1; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. + b === 2; + b === 3; + c === 0; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1 | 2 | 3' and '0'. + c === 1; + c === 2; + c === 3; + d === 0; + d === 1; + d === 2; + d === 3; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '0 | 1 | 2' and '3'. + } + + function f7(a: A, b: B, c: C, d: D) { + a === a; + a === b; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1' and '2 | 3'. + a === c; + a === d; + b === a; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; + } + + function f8(x: 0 | 2 | 4) { + switch (x) { + case 0: return; + case 1: return; + ~ +!!! error TS2678: Type '1' is not comparable to type '0 | 2 | 4'. + case 2: return; + case 3: return; + ~ +!!! error TS2678: Type '3' is not comparable to type '0 | 2 | 4'. + case 4: return; + case 5: return; + ~ +!!! error TS2678: Type '5' is not comparable to type '0 | 2 | 4'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/numericLiteralTypes3.js b/tests/baselines/reference/numericLiteralTypes3.js new file mode 100644 index 00000000000..730314be8ef --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes3.js @@ -0,0 +1,191 @@ +//// [numericLiteralTypes3.ts] +type A = 1; +type B = 2 | 3; +type C = 1 | 2 | 3; +type D = 0 | 1 | 2; + +function f1(a: A, b: B, c: C, d: D) { + a = a; + a = b; + a = c; + a = d; +} + +function f2(a: A, b: B, c: C, d: D) { + b = a; + b = b; + b = c; + b = d; +} + +function f3(a: A, b: B, c: C, d: D) { + c = a; + c = b; + c = c; + c = d; +} + +function f4(a: A, b: B, c: C, d: D) { + d = a; + d = b; + d = c; + d = d; +} + +function f5(a: A, b: B, c: C, d: D) { + a = 0; + a = 1; + a = 2; + a = 3; + b = 0; + b = 1; + b = 2; + b = 3; + c = 0; + c = 1; + c = 2; + c = 3; + d = 0; + d = 1; + d = 2; + d = 3; +} + +function f6(a: A, b: B, c: C, d: D) { + a === 0; + a === 1; + a === 2; + a === 3; + b === 0; + b === 1; + b === 2; + b === 3; + c === 0; + c === 1; + c === 2; + c === 3; + d === 0; + d === 1; + d === 2; + d === 3; +} + +function f7(a: A, b: B, c: C, d: D) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} + +function f8(x: 0 | 2 | 4) { + switch (x) { + case 0: return; + case 1: return; + case 2: return; + case 3: return; + case 4: return; + case 5: return; + } +} + +//// [numericLiteralTypes3.js] +function f1(a, b, c, d) { + a = a; + a = b; + a = c; + a = d; +} +function f2(a, b, c, d) { + b = a; + b = b; + b = c; + b = d; +} +function f3(a, b, c, d) { + c = a; + c = b; + c = c; + c = d; +} +function f4(a, b, c, d) { + d = a; + d = b; + d = c; + d = d; +} +function f5(a, b, c, d) { + a = 0; + a = 1; + a = 2; + a = 3; + b = 0; + b = 1; + b = 2; + b = 3; + c = 0; + c = 1; + c = 2; + c = 3; + d = 0; + d = 1; + d = 2; + d = 3; +} +function f6(a, b, c, d) { + a === 0; + a === 1; + a === 2; + a === 3; + b === 0; + b === 1; + b === 2; + b === 3; + c === 0; + c === 1; + c === 2; + c === 3; + d === 0; + d === 1; + d === 2; + d === 3; +} +function f7(a, b, c, d) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} +function f8(x) { + switch (x) { + case 0: return; + case 1: return; + case 2: return; + case 3: return; + case 4: return; + case 5: return; + } +} diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.js b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.js new file mode 100644 index 00000000000..2c80e8a704e --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.js @@ -0,0 +1,9 @@ +//// [stringLiteralsAssertionsInEqualityComparisons01.ts] +var a = "foo" === "bar" as string; +var b = "foo" !== ("bar" as string); +var c = "foo" == ("bar"); + +//// [stringLiteralsAssertionsInEqualityComparisons01.js] +var a = "foo" === "bar"; +var b = "foo" !== "bar"; +var c = "foo" == "bar"; diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.symbols b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.symbols new file mode 100644 index 00000000000..3affecc854e --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts === +var a = "foo" === "bar" as string; +>a : Symbol(a, Decl(stringLiteralsAssertionsInEqualityComparisons01.ts, 0, 3)) + +var b = "foo" !== ("bar" as string); +>b : Symbol(b, Decl(stringLiteralsAssertionsInEqualityComparisons01.ts, 1, 3)) + +var c = "foo" == ("bar"); +>c : Symbol(c, Decl(stringLiteralsAssertionsInEqualityComparisons01.ts, 2, 3)) + diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types new file mode 100644 index 00000000000..17a835a2461 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts === +var a = "foo" === "bar" as string; +>a : boolean +>"foo" === "bar" as string : boolean +>"foo" : "foo" +>"bar" as string : string +>"bar" : string + +var b = "foo" !== ("bar" as string); +>b : boolean +>"foo" !== ("bar" as string) : boolean +>"foo" : "foo" +>("bar" as string) : string +>"bar" as string : string +>"bar" : string + +var c = "foo" == ("bar"); +>c : boolean +>"foo" == ("bar") : boolean +>"foo" : "foo" +>("bar") : any +>"bar" : any +>"bar" : string + diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt new file mode 100644 index 00000000000..5daeab5dbed --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(3,9): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"baz"'. +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(3,19): error TS2352: Type '"bar"' cannot be converted to type '"baz"'. +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(4,20): error TS2352: Type '"bar"' cannot be converted to type '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(5,9): error TS2365: Operator '==' cannot be applied to types 'string' and 'number'. +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(5,19): error TS2352: Type 'string' cannot be converted to type 'number'. + + +==== tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts (5 errors) ==== + type EnhancedString = string & { enhancements: any }; + + var a = "foo" === "bar" as "baz"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"baz"'. + ~~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar"' cannot be converted to type '"baz"'. + var b = "foo" !== ("bar" as "foo"); + ~~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar"' cannot be converted to type '"foo"'. + var c = "foo" == ("bar"); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types 'string' and 'number'. + ~~~~~~~~~~~~~ +!!! error TS2352: Type 'string' cannot be converted to type 'number'. + var d = "foo" === ("bar" as EnhancedString); \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js new file mode 100644 index 00000000000..32beac89bf7 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js @@ -0,0 +1,13 @@ +//// [stringLiteralsAssertionsInEqualityComparisons02.ts] +type EnhancedString = string & { enhancements: any }; + +var a = "foo" === "bar" as "baz"; +var b = "foo" !== ("bar" as "foo"); +var c = "foo" == ("bar"); +var d = "foo" === ("bar" as EnhancedString); + +//// [stringLiteralsAssertionsInEqualityComparisons02.js] +var a = "foo" === "bar"; +var b = "foo" !== "bar"; +var c = "foo" == "bar"; +var d = "foo" === "bar"; diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt new file mode 100644 index 00000000000..17b4e39e0c5 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(8,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(9,5): error TS2365: Operator '===' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(10,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(17,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(18,5): error TS2365: Operator '!==' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(19,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts (6 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + let b: boolean; + b = x === y; + b = "foo" === y + b = y === "foo"; + b = "foo" === "bar"; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" === x; + ~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"bar"' and '"foo"'. + b = x === "bar"; + ~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. + b = y === "bar"; + b = "bar" === y; + + b = x !== y; + b = "foo" !== y + b = y !== "foo"; + b = "foo" !== "bar"; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" !== x; + ~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"bar"' and '"foo"'. + b = x !== "bar"; + ~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + b = y !== "bar"; + b = "bar" !== y; + + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js new file mode 100644 index 00000000000..fc08a354338 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js @@ -0,0 +1,45 @@ +//// [stringLiteralsWithEqualityChecks01.ts] +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x === y; +b = "foo" === y +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; + +b = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; + + + +//// [stringLiteralsWithEqualityChecks01.js] +var x; +var y; +var b; +b = x === y; +b = "foo" === y; +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; +b = x !== y; +b = "foo" !== y; +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt new file mode 100644 index 00000000000..ef01bbf5109 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(8,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(9,5): error TS2365: Operator '==' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(10,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(17,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(18,5): error TS2365: Operator '!=' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(19,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts (6 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + let b: boolean; + b = x == y; + b = "foo" == y + b = y == "foo"; + b = "foo" == "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" == x; + ~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"bar"' and '"foo"'. + b = x == "bar"; + ~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. + b = y == "bar"; + b = "bar" == y; + + b = x != y; + b = "foo" != y + b = y != "foo"; + b = "foo" != "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" != x; + ~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"bar"' and '"foo"'. + b = x != "bar"; + ~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + b = y != "bar"; + b = "bar" != y; + + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js new file mode 100644 index 00000000000..b31246251a3 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js @@ -0,0 +1,45 @@ +//// [stringLiteralsWithEqualityChecks02.ts] +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; + + + +//// [stringLiteralsWithEqualityChecks02.js] +var x; +var y; +var b; +b = x == y; +b = "foo" == y; +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; +b = x != y; +b = "foo" != y; +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt new file mode 100644 index 00000000000..a12d3f7f0d2 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts(16,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts(25,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts (2 errors) ==== + interface Runnable { + isRunning: boolean; + } + + interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; + } + + let x: string; + let y: "foo" | Refrigerator; + + let b: boolean; + b = x === y; + b = "foo" === y + b = y === "foo"; + b = "foo" === "bar"; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" === x; + b = x === "bar"; + b = y === "bar"; + b = "bar" === y; + + b = x !== y; + b = "foo" !== y + b = y !== "foo"; + b = "foo" !== "bar"; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" !== x; + b = x !== "bar"; + b = y !== "bar"; + b = "bar" !== y; + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js new file mode 100644 index 00000000000..e418c73ff69 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js @@ -0,0 +1,52 @@ +//// [stringLiteralsWithEqualityChecks03.ts] +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; +} + +let x: string; +let y: "foo" | Refrigerator; + +let b: boolean; +b = x === y; +b = "foo" === y +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; + +b = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; + + +//// [stringLiteralsWithEqualityChecks03.js] +var x; +var y; +var b; +b = x === y; +b = "foo" === y; +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; +b = x !== y; +b = "foo" !== y; +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt new file mode 100644 index 00000000000..fde735023d9 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts(16,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts(25,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts (2 errors) ==== + interface Runnable { + isRunning: boolean; + } + + interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; + } + + let x: string; + let y: "foo" | Refrigerator; + + let b: boolean; + b = x == y; + b = "foo" == y + b = y == "foo"; + b = "foo" == "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" == x; + b = x == "bar"; + b = y == "bar"; + b = "bar" == y; + + b = x != y; + b = "foo" != y + b = y != "foo"; + b = "foo" != "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" != x; + b = x != "bar"; + b = y != "bar"; + b = "bar" != y; + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js new file mode 100644 index 00000000000..52f43cdfa5e --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js @@ -0,0 +1,52 @@ +//// [stringLiteralsWithEqualityChecks04.ts] +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; +} + +let x: string; +let y: "foo" | Refrigerator; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; + + +//// [stringLiteralsWithEqualityChecks04.js] +var x; +var y; +var b; +b = x == y; +b = "foo" == y; +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; +b = x != y; +b = "foo" != y; +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt new file mode 100644 index 00000000000..b127d999d94 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts(7,10): error TS2678: Type '"bar"' is not comparable to type '"foo"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts (1 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + switch (x) { + case "foo": + break; + case "bar": + ~~~~~ +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. + break; + case y: + y; + break; + } + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.js new file mode 100644 index 00000000000..b9541ef05e6 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.js @@ -0,0 +1,27 @@ +//// [stringLiteralsWithSwitchStatements01.ts] +let x: "foo"; +let y: "foo" | "bar"; + +switch (x) { + case "foo": + break; + case "bar": + break; + case y: + y; + break; +} + + +//// [stringLiteralsWithSwitchStatements01.js] +var x; +var y; +switch (x) { + case "foo": + break; + case "bar": + break; + case y: + y; + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.errors.txt new file mode 100644 index 00000000000..1a4d9a4c560 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts(8,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts(13,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts (2 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + let b: boolean; + b = x == y; + b = "foo" == y + b = y == "foo"; + b = "foo" == "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. + + b = x != y; + b = "foo" != y + b = y != "foo"; + b = "foo" != "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.js new file mode 100644 index 00000000000..04871615617 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.js @@ -0,0 +1,29 @@ +//// [stringLiteralsWithSwitchStatements02.ts] +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; + + + +//// [stringLiteralsWithSwitchStatements02.js] +var x; +var y; +var b; +b = x == y; +b = "foo" == y; +b = y == "foo"; +b = "foo" == "bar"; +b = x != y; +b = "foo" != y; +b = y != "foo"; +b = "foo" != "bar"; diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt new file mode 100644 index 00000000000..b2cbc96501f --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt @@ -0,0 +1,43 @@ +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts(10,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. + Type '"baz"' is not comparable to type '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts(12,10): error TS2678: Type '"bar"' is not comparable to type '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts(22,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. + Type '"baz"' is not comparable to type '"foo"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts (3 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + let z: "bar"; + + declare function randBool(): boolean; + + switch (x) { + case randBool() ? "foo" : "baz": + break; + case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. +!!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. + break; + case (("bar")): + ~~~~~~~~~ +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. + break; + case (x, y, ("baz")): + x; + y; + break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + ~~~~~~~~~~ +!!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. +!!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. + case "baz" || z: + z; + break; + } + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.js new file mode 100644 index 00000000000..17596249e6c --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.js @@ -0,0 +1,53 @@ +//// [stringLiteralsWithSwitchStatements03.ts] +let x: "foo"; +let y: "foo" | "bar"; +let z: "bar"; + +declare function randBool(): boolean; + +switch (x) { + case randBool() ? "foo" : "baz": + break; + case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): + break; + case (("bar")): + break; + case (x, y, ("baz")): + x; + y; + break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + case "baz" || z: + z; + break; +} + + +//// [stringLiteralsWithSwitchStatements03.js] +var x; +var y; +var z; +switch (x) { + case randBool() ? "foo" : "baz": + break; + case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): + break; + case (("bar")): + break; + case (x, y, ("baz")): + x; + y; + break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + case "baz" || z: + z; + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.js new file mode 100644 index 00000000000..da2ce7b4150 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.js @@ -0,0 +1,43 @@ +//// [stringLiteralsWithSwitchStatements04.ts] +let x: "foo"; +let y: "foo" | "bar"; + +declare function randBool(): boolean; + +switch (y) { + case "foo", x: + break; + case x, "foo": + break; + case x, "baz": + break; + case "baz", x: + break; + case "baz" && "bar": + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} + + +//// [stringLiteralsWithSwitchStatements04.js] +var x; +var y; +switch (y) { + case "foo", x: + break; + case x, "foo": + break; + case x, "baz": + break; + case "baz", x: + break; + case "baz" && "bar": + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols new file mode 100644 index 00000000000..40062a34b47 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts === +let x: "foo"; +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + +let y: "foo" | "bar"; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements04.ts, 1, 3)) + +declare function randBool(): boolean; +>randBool : Symbol(randBool, Decl(stringLiteralsWithSwitchStatements04.ts, 1, 21)) + +switch (y) { +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements04.ts, 1, 3)) + + case "foo", x: +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + break; + case x, "foo": +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + break; + case x, "baz": +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + break; + case "baz", x: +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + break; + case "baz" && "bar": + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} + diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types new file mode 100644 index 00000000000..fc395576a72 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types @@ -0,0 +1,63 @@ +=== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts === +let x: "foo"; +>x : "foo" + +let y: "foo" | "bar"; +>y : "foo" | "bar" + +declare function randBool(): boolean; +>randBool : () => boolean + +switch (y) { +>y : "foo" | "bar" + + case "foo", x: +>"foo", x : "foo" +>"foo" : string +>x : "foo" + + break; + case x, "foo": +>x, "foo" : string +>x : "foo" +>"foo" : string + + break; + case x, "baz": +>x, "baz" : string +>x : "foo" +>"baz" : string + + break; + case "baz", x: +>"baz", x : "foo" +>"baz" : string +>x : "foo" + + break; + case "baz" && "bar": +>"baz" && "bar" : string +>"baz" : string +>"bar" : string + + break; + case "baz" && ("foo" || "bar"): +>"baz" && ("foo" || "bar") : string +>"baz" : string +>("foo" || "bar") : string +>"foo" || "bar" : string +>"foo" : string +>"bar" : string + + break; + case "bar" && ("baz" || "bar"): +>"bar" && ("baz" || "bar") : string +>"bar" : string +>("baz" || "bar") : string +>"baz" || "bar" : string +>"baz" : string +>"bar" : string + + break; +} + diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt new file mode 100644 index 00000000000..d9d465c7afc --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts(3,9): error TS2352: Type '"foo"' cannot be converted to type '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts(4,9): error TS2352: Type '"bar"' cannot be converted to type '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts(7,9): error TS2352: Type '"foo" | "bar"' cannot be converted to type '"baz"'. + Type '"bar"' is not comparable to type '"baz"'. +tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts(8,9): error TS2352: Type '"baz"' cannot be converted to type '"foo" | "bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts (4 errors) ==== + let fooOrBar: "foo" | "bar"; + + let a = "foo" as "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2352: Type '"foo"' cannot be converted to type '"bar"'. + let b = "bar" as "foo"; + ~~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar"' cannot be converted to type '"foo"'. + let c = fooOrBar as "foo"; + let d = fooOrBar as "bar"; + let e = fooOrBar as "baz"; + ~~~~~~~~~~~~~~~~~ +!!! error TS2352: Type '"foo" | "bar"' cannot be converted to type '"baz"'. +!!! error TS2352: Type '"bar"' is not comparable to type '"baz"'. + let f = "baz" as typeof fooOrBar; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Type '"baz"' cannot be converted to type '"foo" | "bar"'. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.js b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.js new file mode 100644 index 00000000000..6e74c737517 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.js @@ -0,0 +1,18 @@ +//// [stringLiteralsWithTypeAssertions01.ts] +let fooOrBar: "foo" | "bar"; + +let a = "foo" as "bar"; +let b = "bar" as "foo"; +let c = fooOrBar as "foo"; +let d = fooOrBar as "bar"; +let e = fooOrBar as "baz"; +let f = "baz" as typeof fooOrBar; + +//// [stringLiteralsWithTypeAssertions01.js] +var fooOrBar; +var a = "foo"; +var b = "bar"; +var c = fooOrBar; +var d = fooOrBar; +var e = fooOrBar; +var f = "baz";