mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fixed false positive circular errors for await expressions with simple non-generic calls in CFA loops (#51126)
This commit is contained in:
@@ -39,7 +39,6 @@ interface A {
|
||||
function foo(x: A): string { return "abc"; }
|
||||
|
||||
class C {
|
||||
// Error expected
|
||||
s = foo(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
// @strict: true
|
||||
// @noEmit: true
|
||||
// @lib: esnext
|
||||
|
||||
let cond: boolean;
|
||||
|
||||
async function len(s: string) {
|
||||
return s.length;
|
||||
}
|
||||
|
||||
async function f1() {
|
||||
let x: string | number | boolean;
|
||||
x = "";
|
||||
while (cond) {
|
||||
x = await len(x);
|
||||
x;
|
||||
}
|
||||
x;
|
||||
}
|
||||
|
||||
async function f2() {
|
||||
let x: string | number | boolean;
|
||||
x = "";
|
||||
while (cond) {
|
||||
x;
|
||||
x = await len(x);
|
||||
}
|
||||
x;
|
||||
}
|
||||
|
||||
declare function foo(x: string): Promise<number>;
|
||||
declare function foo(x: number): Promise<string>;
|
||||
|
||||
async function g1() {
|
||||
let x: string | number | boolean;
|
||||
x = "";
|
||||
while (cond) {
|
||||
x = await foo(x);
|
||||
x;
|
||||
}
|
||||
x;
|
||||
}
|
||||
|
||||
async function g2() {
|
||||
let x: string | number | boolean;
|
||||
x = "";
|
||||
while (cond) {
|
||||
x;
|
||||
x = await foo(x);
|
||||
}
|
||||
x;
|
||||
}
|
||||
|
||||
async function asNumber(x: string | number): Promise<number> {
|
||||
return +x;
|
||||
}
|
||||
|
||||
async function h1() {
|
||||
let x: string | number | boolean;
|
||||
x = "0";
|
||||
while (cond) {
|
||||
x = +x + 1;
|
||||
x;
|
||||
}
|
||||
}
|
||||
|
||||
async function h2() {
|
||||
let x: string | number | boolean;
|
||||
x = "0";
|
||||
while (cond) {
|
||||
x = await asNumber(x) + 1;
|
||||
x;
|
||||
}
|
||||
}
|
||||
|
||||
async function h3() {
|
||||
let x: string | number | boolean;
|
||||
x = "0";
|
||||
while (cond) {
|
||||
let y = await asNumber(x);
|
||||
x = y + 1;
|
||||
x;
|
||||
}
|
||||
}
|
||||
|
||||
async function h4() {
|
||||
let x: string | number | boolean;
|
||||
x = "0";
|
||||
while (cond) {
|
||||
x;
|
||||
let y = await asNumber(x);
|
||||
x = y + 1;
|
||||
x;
|
||||
}
|
||||
}
|
||||
|
||||
// repro #51115
|
||||
|
||||
async function get_things(_: number | undefined) {
|
||||
return [0];
|
||||
}
|
||||
|
||||
async function foobar() {
|
||||
let before: number | undefined = undefined;
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const results = await get_things(before);
|
||||
before = results[0];
|
||||
}
|
||||
}
|
||||
|
||||
// repro #43047#issuecomment-821453073
|
||||
|
||||
declare function foox(x: string | undefined): Promise<string>
|
||||
|
||||
async () => {
|
||||
let bar: string | undefined = undefined;
|
||||
do {
|
||||
const baz = await foox(bar);
|
||||
bar = baz
|
||||
} while (bar)
|
||||
}
|
||||
|
||||
// repro #43047#issuecomment-874221939
|
||||
|
||||
declare function myQuery(input: { lastId: number | undefined }): Promise<{ entities: number[] }>;
|
||||
|
||||
async function myFunc(): Promise<void> {
|
||||
let lastId: number | undefined = undefined;
|
||||
|
||||
while (true) {
|
||||
const { entities } = await myQuery({
|
||||
lastId,
|
||||
});
|
||||
|
||||
lastId = entities[entities.length - 1];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user