Skip to content

Control flow analysis for implicit any variables #11263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
ahejlsberg committed Sep 29, 2016
commit d8ec85775ae80d0f497ab281ad99af8930410bc9
119 changes: 119 additions & 0 deletions tests/cases/compiler/controlFlowLetVar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// @strictNullChecks: true

declare let cond: boolean;

function f1() {
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice if these functions had names that showed what they were testing.

let x;
if (cond) {
x = 1;
}
if (cond) {
x = "hello";
}
const y = x;
Copy link
Member

Choose a reason for hiding this comment

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

if you have if (cond) .. else then y: string | number, right? Might be nice to have a case for that.

}

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;
};
}
120 changes: 120 additions & 0 deletions tests/cases/compiler/controlFlowNoImplicitAny.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// @strictNullChecks: true
// @noImplicitAny: true

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;
};
}