Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Mar 3, 2017
1 parent 6995055 commit c2431ad
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/baselines/reference/circularInferredTypeOfVariable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//// [circularInferredTypeOfVariable.ts]

// Repro from #14428

(async () => {
function foo(p: string[]): string[] {
return [];
}

function bar(p: string[]): string[] {
return [];
}

let a1: string[] | undefined = [];

while (true) {
let a2 = foo(a1!);
a1 = await bar(a2);
}
});

//// [circularInferredTypeOfVariable.js]
// Repro from #14428
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
(() => __awaiter(this, void 0, void 0, function* () {
function foo(p) {
return [];
}
function bar(p) {
return [];
}
let a1 = [];
while (true) {
let a2 = foo(a1);
a1 = yield bar(a2);
}
}));
34 changes: 34 additions & 0 deletions tests/baselines/reference/circularInferredTypeOfVariable.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
=== tests/cases/compiler/circularInferredTypeOfVariable.ts ===

// Repro from #14428

(async () => {
function foo(p: string[]): string[] {
>foo : Symbol(foo, Decl(circularInferredTypeOfVariable.ts, 3, 14))
>p : Symbol(p, Decl(circularInferredTypeOfVariable.ts, 4, 17))

return [];
}

function bar(p: string[]): string[] {
>bar : Symbol(bar, Decl(circularInferredTypeOfVariable.ts, 6, 5))
>p : Symbol(p, Decl(circularInferredTypeOfVariable.ts, 8, 17))

return [];
}

let a1: string[] | undefined = [];
>a1 : Symbol(a1, Decl(circularInferredTypeOfVariable.ts, 12, 7))

while (true) {
let a2 = foo(a1!);
>a2 : Symbol(a2, Decl(circularInferredTypeOfVariable.ts, 15, 11))
>foo : Symbol(foo, Decl(circularInferredTypeOfVariable.ts, 3, 14))
>a1 : Symbol(a1, Decl(circularInferredTypeOfVariable.ts, 12, 7))

a1 = await bar(a2);
>a1 : Symbol(a1, Decl(circularInferredTypeOfVariable.ts, 12, 7))
>bar : Symbol(bar, Decl(circularInferredTypeOfVariable.ts, 6, 5))
>a2 : Symbol(a2, Decl(circularInferredTypeOfVariable.ts, 15, 11))
}
});
47 changes: 47 additions & 0 deletions tests/baselines/reference/circularInferredTypeOfVariable.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
=== tests/cases/compiler/circularInferredTypeOfVariable.ts ===

// Repro from #14428

(async () => {
>(async () => { function foo(p: string[]): string[] { return []; } function bar(p: string[]): string[] { return []; } let a1: string[] | undefined = []; while (true) { let a2 = foo(a1!); a1 = await bar(a2); }}) : () => Promise<never>
>async () => { function foo(p: string[]): string[] { return []; } function bar(p: string[]): string[] { return []; } let a1: string[] | undefined = []; while (true) { let a2 = foo(a1!); a1 = await bar(a2); }} : () => Promise<never>

function foo(p: string[]): string[] {
>foo : (p: string[]) => string[]
>p : string[]

return [];
>[] : undefined[]
}

function bar(p: string[]): string[] {
>bar : (p: string[]) => string[]
>p : string[]

return [];
>[] : undefined[]
}

let a1: string[] | undefined = [];
>a1 : string[]
>[] : undefined[]

while (true) {
>true : true

let a2 = foo(a1!);
>a2 : string[]
>foo(a1!) : string[]
>foo : (p: string[]) => string[]
>a1! : string[]
>a1 : string[]

a1 = await bar(a2);
>a1 = await bar(a2) : string[]
>a1 : string[]
>await bar(a2) : string[]
>bar(a2) : string[]
>bar : (p: string[]) => string[]
>a2 : string[]
}
});
20 changes: 20 additions & 0 deletions tests/cases/compiler/circularInferredTypeOfVariable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @target: es6

// Repro from #14428

(async () => {
function foo(p: string[]): string[] {
return [];
}

function bar(p: string[]): string[] {
return [];
}

let a1: string[] | undefined = [];

while (true) {
let a2 = foo(a1!);
a1 = await bar(a2);
}
});

0 comments on commit c2431ad

Please sign in to comment.