diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e3a0fee79b3e7..166220f90081e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -465,7 +465,7 @@ namespace ts { let deferredGlobalImportMetaType: ObjectType; let deferredGlobalExtractSymbol: Symbol; - let deferredNodes: Node[] | undefined; + let deferredNodes: Map | undefined; const allPotentiallyUnusedIdentifiers = createMap(); // key is file name let flowLoopStart = 0; @@ -26070,12 +26070,13 @@ namespace ts { // Delaying the type check of the body ensures foo has been assigned a type. function checkNodeDeferred(node: Node) { if (deferredNodes) { - deferredNodes.push(node); + const id = "" + getNodeId(node); + deferredNodes.set(id, node); } } function checkDeferredNodes() { - for (const node of deferredNodes!) { + deferredNodes!.forEach(node => { switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: @@ -26091,7 +26092,7 @@ namespace ts { checkClassExpressionDeferred(node); break; } - } + }); } function checkSourceFile(node: SourceFile) { @@ -26133,7 +26134,7 @@ namespace ts { clear(potentialThisCollisions); clear(potentialNewTargetCollisions); - deferredNodes = []; + deferredNodes = createMap(); forEach(node.statements, checkSourceElement); checkDeferredNodes(); diff --git a/tests/baselines/reference/checkSpecialPropertyAssignments.errors.txt b/tests/baselines/reference/checkSpecialPropertyAssignments.errors.txt new file mode 100644 index 0000000000000..6e4e3f3830503 --- /dev/null +++ b/tests/baselines/reference/checkSpecialPropertyAssignments.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/salsa/bug24252.js(8,9): error TS2322: Type 'string[]' is not assignable to type 'number[]'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/salsa/bug24252.js (1 errors) ==== + var A = {}; + A.B = class { + m() { + /** @type {string[]} */ + var x = []; + /** @type {number[]} */ + var y; + y = x; + ~ +!!! error TS2322: Type 'string[]' is not assignable to type 'number[]'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + } + }; + \ No newline at end of file diff --git a/tests/baselines/reference/checkSpecialPropertyAssignments.symbols b/tests/baselines/reference/checkSpecialPropertyAssignments.symbols new file mode 100644 index 0000000000000..8de3cd208c325 --- /dev/null +++ b/tests/baselines/reference/checkSpecialPropertyAssignments.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/salsa/bug24252.js === +var A = {}; +>A : Symbol(A, Decl(bug24252.js, 0, 3), Decl(bug24252.js, 0, 11)) + +A.B = class { +>A.B : Symbol(A.B, Decl(bug24252.js, 0, 11)) +>A : Symbol(A, Decl(bug24252.js, 0, 3), Decl(bug24252.js, 0, 11)) +>B : Symbol(A.B, Decl(bug24252.js, 0, 11)) + + m() { +>m : Symbol(B.m, Decl(bug24252.js, 1, 13)) + + /** @type {string[]} */ + var x = []; +>x : Symbol(x, Decl(bug24252.js, 4, 11)) + + /** @type {number[]} */ + var y; +>y : Symbol(y, Decl(bug24252.js, 6, 11)) + + y = x; +>y : Symbol(y, Decl(bug24252.js, 6, 11)) +>x : Symbol(x, Decl(bug24252.js, 4, 11)) + } +}; + diff --git a/tests/baselines/reference/checkSpecialPropertyAssignments.types b/tests/baselines/reference/checkSpecialPropertyAssignments.types new file mode 100644 index 0000000000000..879038b6f9471 --- /dev/null +++ b/tests/baselines/reference/checkSpecialPropertyAssignments.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/salsa/bug24252.js === +var A = {}; +>A : typeof A +>{} : { [x: string]: any; } + +A.B = class { +>A.B = class { m() { /** @type {string[]} */ var x = []; /** @type {number[]} */ var y; y = x; }} : typeof B +>A.B : typeof B +>A : typeof A +>B : typeof B +>class { m() { /** @type {string[]} */ var x = []; /** @type {number[]} */ var y; y = x; }} : typeof B + + m() { +>m : () => void + + /** @type {string[]} */ + var x = []; +>x : string[] +>[] : undefined[] + + /** @type {number[]} */ + var y; +>y : number[] + + y = x; +>y = x : string[] +>y : number[] +>x : string[] + } +}; + diff --git a/tests/cases/conformance/salsa/checkSpecialPropertyAssignments.ts b/tests/cases/conformance/salsa/checkSpecialPropertyAssignments.ts new file mode 100644 index 0000000000000..31ba8fbd9becf --- /dev/null +++ b/tests/cases/conformance/salsa/checkSpecialPropertyAssignments.ts @@ -0,0 +1,14 @@ +// @noEmit: true +// @checkJs: true +// @allowJs: true +// @Filename: bug24252.js +var A = {}; +A.B = class { + m() { + /** @type {string[]} */ + var x = []; + /** @type {number[]} */ + var y; + y = x; + } +};