TypeScript/tests/baselines/reference/dependentDestructuredVariables.symbols
Anders Hejlsberg 831b770b95
Control flow analysis for destructured discriminated unions (#46266)
* CFA for dependent variables destructured from discriminated union

* Accept new baselines

* Add tests

* Limit calls to isSymbolAssigned

* Fix wrong operator
2021-11-02 15:48:13 -07:00

410 lines
18 KiB
Plaintext

=== tests/cases/conformance/controlFlow/dependentDestructuredVariables.ts ===
type Action =
>Action : Symbol(Action, Decl(dependentDestructuredVariables.ts, 0, 0))
| { kind: 'A', payload: number }
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 1, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 1, 18))
| { kind: 'B', payload: string };
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 2, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 2, 18))
function f10({ kind, payload }: Action) {
>f10 : Symbol(f10, Decl(dependentDestructuredVariables.ts, 2, 37))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 4, 14))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 4, 20))
>Action : Symbol(Action, Decl(dependentDestructuredVariables.ts, 0, 0))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 4, 14))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 4, 20))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 4, 14))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 4, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
function f11(action: Action) {
>f11 : Symbol(f11, Decl(dependentDestructuredVariables.ts, 11, 1))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 13, 13))
>Action : Symbol(Action, Decl(dependentDestructuredVariables.ts, 0, 0))
const { kind, payload } = action;
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 14, 11))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 14, 17))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 13, 13))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 14, 11))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 14, 17))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 14, 11))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 14, 17))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
function f12({ kind, payload }: Action) {
>f12 : Symbol(f12, Decl(dependentDestructuredVariables.ts, 21, 1))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 23, 14))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 23, 20))
>Action : Symbol(Action, Decl(dependentDestructuredVariables.ts, 0, 0))
switch (kind) {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 23, 14))
case 'A':
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 23, 20))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
break;
case 'B':
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 23, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
break;
default:
payload; // never
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 23, 20))
}
}
type Action2 =
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
| { kind: 'A', payload: number | undefined }
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 37, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 37, 18))
| { kind: 'B', payload: string | undefined };
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 38, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 38, 18))
function f20({ kind, payload }: Action2) {
>f20 : Symbol(f20, Decl(dependentDestructuredVariables.ts, 38, 49))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 40, 14))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 40, 20))
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
if (payload) {
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 40, 20))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 40, 14))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 40, 20))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 40, 14))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 40, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
}
function f21(action: Action2) {
>f21 : Symbol(f21, Decl(dependentDestructuredVariables.ts, 49, 1))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 51, 13))
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
const { kind, payload } = action;
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 52, 11))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 52, 17))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 51, 13))
if (payload) {
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 52, 17))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 52, 11))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 52, 17))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 52, 11))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 52, 17))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
}
function f22(action: Action2) {
>f22 : Symbol(f22, Decl(dependentDestructuredVariables.ts, 61, 1))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 63, 13))
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
if (action.payload) {
>action.payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 37, 18), Decl(dependentDestructuredVariables.ts, 38, 18))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 63, 13))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 37, 18), Decl(dependentDestructuredVariables.ts, 38, 18))
const { kind, payload } = action;
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 65, 15))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 65, 21))
>action : Symbol(action, Decl(dependentDestructuredVariables.ts, 63, 13))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 65, 15))
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 65, 21))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 65, 15))
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 65, 21))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
}
}
}
function f23({ kind, payload }: Action2) {
>f23 : Symbol(f23, Decl(dependentDestructuredVariables.ts, 73, 1))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 75, 14))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
>Action2 : Symbol(Action2, Decl(dependentDestructuredVariables.ts, 34, 1))
if (payload) {
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
switch (kind) {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 75, 14))
case 'A':
payload.toFixed();
>payload.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
>toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --))
break;
case 'B':
payload.toUpperCase();
>payload.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
break;
default:
payload; // never
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 75, 20))
}
}
}
type Foo =
>Foo : Symbol(Foo, Decl(dependentDestructuredVariables.ts, 88, 1))
| { kind: 'A', isA: true }
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 91, 7))
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 91, 18))
| { kind: 'B', isA: false }
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 92, 7))
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 92, 18))
| { kind: 'C', isA: false };
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 93, 7))
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 93, 18))
function f30({ kind, isA }: Foo) {
>f30 : Symbol(f30, Decl(dependentDestructuredVariables.ts, 93, 32))
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
>Foo : Symbol(Foo, Decl(dependentDestructuredVariables.ts, 88, 1))
if (kind === 'A') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
isA; // true
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
}
if (kind === 'B') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
isA; // false
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
}
if (kind === 'C') {
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
isA; // false
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
}
if (isA) {
>isA : Symbol(isA, Decl(dependentDestructuredVariables.ts, 95, 20))
kind; // 'A'
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
}
else {
kind; // 'B' | 'C'
>kind : Symbol(kind, Decl(dependentDestructuredVariables.ts, 95, 14))
}
}
// Repro from #35283
interface A<T> { variant: 'a', value: T }
>A : Symbol(A, Decl(dependentDestructuredVariables.ts, 111, 1))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 115, 12))
>variant : Symbol(A.variant, Decl(dependentDestructuredVariables.ts, 115, 16))
>value : Symbol(A.value, Decl(dependentDestructuredVariables.ts, 115, 30))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 115, 12))
interface B<T> { variant: 'b', value: Array<T> }
>B : Symbol(B, Decl(dependentDestructuredVariables.ts, 115, 41))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 117, 12))
>variant : Symbol(B.variant, Decl(dependentDestructuredVariables.ts, 117, 16))
>value : Symbol(B.value, Decl(dependentDestructuredVariables.ts, 117, 30))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 117, 12))
type AB<T> = A<T> | B<T>;
>AB : Symbol(AB, Decl(dependentDestructuredVariables.ts, 117, 48))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 119, 8))
>A : Symbol(A, Decl(dependentDestructuredVariables.ts, 111, 1))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 119, 8))
>B : Symbol(B, Decl(dependentDestructuredVariables.ts, 115, 41))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 119, 8))
declare function printValue<T>(t: T): void;
>printValue : Symbol(printValue, Decl(dependentDestructuredVariables.ts, 119, 25))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 121, 28))
>t : Symbol(t, Decl(dependentDestructuredVariables.ts, 121, 31))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 121, 28))
declare function printValueList<T>(t: Array<T>): void;
>printValueList : Symbol(printValueList, Decl(dependentDestructuredVariables.ts, 121, 43))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 123, 32))
>t : Symbol(t, Decl(dependentDestructuredVariables.ts, 123, 35))
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 123, 32))
function unrefined1<T>(ab: AB<T>): void {
>unrefined1 : Symbol(unrefined1, Decl(dependentDestructuredVariables.ts, 123, 54))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 125, 20))
>ab : Symbol(ab, Decl(dependentDestructuredVariables.ts, 125, 23))
>AB : Symbol(AB, Decl(dependentDestructuredVariables.ts, 117, 48))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 125, 20))
const { variant, value } = ab;
>variant : Symbol(variant, Decl(dependentDestructuredVariables.ts, 126, 11))
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 126, 20))
>ab : Symbol(ab, Decl(dependentDestructuredVariables.ts, 125, 23))
if (variant === 'a') {
>variant : Symbol(variant, Decl(dependentDestructuredVariables.ts, 126, 11))
printValue<T>(value);
>printValue : Symbol(printValue, Decl(dependentDestructuredVariables.ts, 119, 25))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 125, 20))
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 126, 20))
}
else {
printValueList<T>(value);
>printValueList : Symbol(printValueList, Decl(dependentDestructuredVariables.ts, 121, 43))
>T : Symbol(T, Decl(dependentDestructuredVariables.ts, 125, 20))
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 126, 20))
}
}
// Repro from #38020
type Action3 =
>Action3 : Symbol(Action3, Decl(dependentDestructuredVariables.ts, 133, 1))
| {type: 'add', payload: { toAdd: number } }
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 138, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 138, 19))
>toAdd : Symbol(toAdd, Decl(dependentDestructuredVariables.ts, 138, 30))
| {type: 'remove', payload: { toRemove: number } };
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 139, 7))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 139, 22))
>toRemove : Symbol(toRemove, Decl(dependentDestructuredVariables.ts, 139, 33))
const reducerBroken = (state: number, { type, payload }: Action3) => {
>reducerBroken : Symbol(reducerBroken, Decl(dependentDestructuredVariables.ts, 141, 5))
>state : Symbol(state, Decl(dependentDestructuredVariables.ts, 141, 23))
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 141, 39))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 141, 45))
>Action3 : Symbol(Action3, Decl(dependentDestructuredVariables.ts, 133, 1))
switch (type) {
>type : Symbol(type, Decl(dependentDestructuredVariables.ts, 141, 39))
case 'add':
return state + payload.toAdd;
>state : Symbol(state, Decl(dependentDestructuredVariables.ts, 141, 23))
>payload.toAdd : Symbol(toAdd, Decl(dependentDestructuredVariables.ts, 138, 30))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 141, 45))
>toAdd : Symbol(toAdd, Decl(dependentDestructuredVariables.ts, 138, 30))
case 'remove':
return state - payload.toRemove;
>state : Symbol(state, Decl(dependentDestructuredVariables.ts, 141, 23))
>payload.toRemove : Symbol(toRemove, Decl(dependentDestructuredVariables.ts, 139, 33))
>payload : Symbol(payload, Decl(dependentDestructuredVariables.ts, 141, 45))
>toRemove : Symbol(toRemove, Decl(dependentDestructuredVariables.ts, 139, 33))
}
}
// Repro from #46143
declare var it: Iterator<number>;
>it : Symbol(it, Decl(dependentDestructuredVariables.ts, 152, 11))
>Iterator : Symbol(Iterator, Decl(lib.es2015.iterable.d.ts, --, --))
const { value, done } = it.next();
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 153, 7))
>done : Symbol(done, Decl(dependentDestructuredVariables.ts, 153, 14))
>it.next : Symbol(Iterator.next, Decl(lib.es2015.iterable.d.ts, --, --))
>it : Symbol(it, Decl(dependentDestructuredVariables.ts, 152, 11))
>next : Symbol(Iterator.next, Decl(lib.es2015.iterable.d.ts, --, --))
if (!done) {
>done : Symbol(done, Decl(dependentDestructuredVariables.ts, 153, 14))
value; // number
>value : Symbol(value, Decl(dependentDestructuredVariables.ts, 153, 7))
}