diff --git a/tests/baselines/reference/controlFlowLetVar.js b/tests/baselines/reference/controlFlowLetVar.js new file mode 100644 index 00000000000..6fe9450dd8a --- /dev/null +++ b/tests/baselines/reference/controlFlowLetVar.js @@ -0,0 +1,227 @@ +//// [controlFlowLetVar.ts] + +declare let cond: boolean; + +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + function f() { + const z = x; + } +} + +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + const f = () => { + const z = x; + }; +} + +//// [controlFlowLetVar.js] +function f1() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f2() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f3() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f4() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f8() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f9() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; + function f() { + var z = x; + } +} +function f10() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; + var f = function () { + var z = x; + }; +} diff --git a/tests/baselines/reference/controlFlowLetVar.symbols b/tests/baselines/reference/controlFlowLetVar.symbols new file mode 100644 index 00000000000..5cff2938646 --- /dev/null +++ b/tests/baselines/reference/controlFlowLetVar.symbols @@ -0,0 +1,253 @@ +=== tests/cases/compiler/controlFlowLetVar.ts === + +declare let cond: boolean; +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + +function f1() { +>f1 : Symbol(f1, Decl(controlFlowLetVar.ts, 1, 26)) + + let x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 4, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 4, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 4, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 11, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 4, 7)) +} + +function f2() { +>f2 : Symbol(f2, Decl(controlFlowLetVar.ts, 12, 1)) + + let x = undefined; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 15, 7)) +>undefined : Symbol(undefined) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 15, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 15, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 22, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 15, 7)) +} + +function f3() { +>f3 : Symbol(f3, Decl(controlFlowLetVar.ts, 23, 1)) + + let x = null; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 26, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 26, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 26, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 33, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 26, 7)) +} + +function f4() { +>f4 : Symbol(f4, Decl(controlFlowLetVar.ts, 34, 1)) + + let x: any; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 37, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 37, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 37, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 44, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 37, 7)) +} + +function f5() { +>f5 : Symbol(f5, Decl(controlFlowLetVar.ts, 45, 1)) + + var x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 48, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 48, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 48, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 55, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 48, 7)) +} + +function f6() { +>f6 : Symbol(f6, Decl(controlFlowLetVar.ts, 56, 1)) + + var x = undefined; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 59, 7)) +>undefined : Symbol(undefined) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 59, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 59, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 66, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 59, 7)) +} + +function f7() { +>f7 : Symbol(f7, Decl(controlFlowLetVar.ts, 67, 1)) + + var x = null; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 70, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 70, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 70, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 77, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 70, 7)) +} + +function f8() { +>f8 : Symbol(f8, Decl(controlFlowLetVar.ts, 78, 1)) + + var x: any; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 81, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 81, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 81, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 88, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 81, 7)) +} + +function f9() { +>f9 : Symbol(f9, Decl(controlFlowLetVar.ts, 89, 1)) + + let x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 92, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 92, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 92, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 99, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 92, 7)) + + function f() { +>f : Symbol(f, Decl(controlFlowLetVar.ts, 99, 16)) + + const z = x; +>z : Symbol(z, Decl(controlFlowLetVar.ts, 101, 13)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 92, 7)) + } +} + +function f10() { +>f10 : Symbol(f10, Decl(controlFlowLetVar.ts, 103, 1)) + + let x; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 106, 7)) + + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = 1; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 106, 7)) + } + if (cond) { +>cond : Symbol(cond, Decl(controlFlowLetVar.ts, 1, 11)) + + x = "hello"; +>x : Symbol(x, Decl(controlFlowLetVar.ts, 106, 7)) + } + const y = x; +>y : Symbol(y, Decl(controlFlowLetVar.ts, 113, 9)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 106, 7)) + + const f = () => { +>f : Symbol(f, Decl(controlFlowLetVar.ts, 114, 9)) + + const z = x; +>z : Symbol(z, Decl(controlFlowLetVar.ts, 115, 13)) +>x : Symbol(x, Decl(controlFlowLetVar.ts, 106, 7)) + + }; +} diff --git a/tests/baselines/reference/controlFlowLetVar.types b/tests/baselines/reference/controlFlowLetVar.types new file mode 100644 index 00000000000..954f8b803ee --- /dev/null +++ b/tests/baselines/reference/controlFlowLetVar.types @@ -0,0 +1,296 @@ +=== tests/cases/compiler/controlFlowLetVar.ts === + +declare let cond: boolean; +>cond : boolean + +function f1() { +>f1 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : string | number | undefined +>x : string | number | undefined +} + +function f2() { +>f2 : () => void + + let x = undefined; +>x : any +>undefined : undefined + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : string | number | undefined +>x : string | number | undefined +} + +function f3() { +>f3 : () => void + + let x = null; +>x : any +>null : null + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : string | number | null +>x : string | number | null +} + +function f4() { +>f4 : () => void + + let x: any; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : any +>x : any +} + +function f5() { +>f5 : () => void + + var x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : string | number | undefined +>x : string | number | undefined +} + +function f6() { +>f6 : () => void + + var x = undefined; +>x : any +>undefined : undefined + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : string | number | undefined +>x : string | number | undefined +} + +function f7() { +>f7 : () => void + + var x = null; +>x : any +>null : null + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : string | number | null +>x : string | number | null +} + +function f8() { +>f8 : () => void + + var x: any; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : any +>x : any +} + +function f9() { +>f9 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : string | number | undefined +>x : string | number | undefined + + function f() { +>f : () => void + + const z = x; +>z : any +>x : any + } +} + +function f10() { +>f10 : () => void + + let x; +>x : any + + if (cond) { +>cond : boolean + + x = 1; +>x = 1 : 1 +>x : any +>1 : 1 + } + if (cond) { +>cond : boolean + + x = "hello"; +>x = "hello" : "hello" +>x : any +>"hello" : "hello" + } + const y = x; +>y : string | number | undefined +>x : string | number | undefined + + const f = () => { +>f : () => void +>() => { const z = x; } : () => void + + const z = x; +>z : any +>x : any + + }; +} diff --git a/tests/baselines/reference/controlFlowNoImplicitAny.errors.txt b/tests/baselines/reference/controlFlowNoImplicitAny.errors.txt new file mode 100644 index 00000000000..fbe87a8edf8 --- /dev/null +++ b/tests/baselines/reference/controlFlowNoImplicitAny.errors.txt @@ -0,0 +1,133 @@ +tests/cases/compiler/controlFlowNoImplicitAny.ts(93,9): error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. +tests/cases/compiler/controlFlowNoImplicitAny.ts(102,19): error TS7005: Variable 'x' implicitly has an 'any' type. +tests/cases/compiler/controlFlowNoImplicitAny.ts(107,9): error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. +tests/cases/compiler/controlFlowNoImplicitAny.ts(116,19): error TS7005: Variable 'x' implicitly has an 'any' type. + + +==== tests/cases/compiler/controlFlowNoImplicitAny.ts (4 errors) ==== + + declare let cond: boolean; + + function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + } + + function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + } + + function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + } + + function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + } + + function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + } + + function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + } + + function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + } + + function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + } + + function f9() { + let x; + ~ +!!! error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + function f() { + const z = x; + ~ +!!! error TS7005: Variable 'x' implicitly has an 'any' type. + } + } + + function f10() { + let x; + ~ +!!! error TS7034: Variable 'x' implicitly has type 'any' in some locations where its type cannot be determined. + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + const f = () => { + const z = x; + ~ +!!! error TS7005: Variable 'x' implicitly has an 'any' type. + }; + } \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowNoImplicitAny.js b/tests/baselines/reference/controlFlowNoImplicitAny.js new file mode 100644 index 00000000000..0c5a77420f6 --- /dev/null +++ b/tests/baselines/reference/controlFlowNoImplicitAny.js @@ -0,0 +1,227 @@ +//// [controlFlowNoImplicitAny.ts] + +declare let cond: boolean; + +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + function f() { + const z = x; + } +} + +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + const f = () => { + const z = x; + }; +} + +//// [controlFlowNoImplicitAny.js] +function f1() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f2() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f3() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f4() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f8() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; +} +function f9() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; + function f() { + var z = x; + } +} +function f10() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + var y = x; + var f = function () { + var z = x; + }; +}