Skip to content

Fix duplicate errors in js special assignments #24508

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 6 commits into from
Jun 26, 2018
Merged
Changes from all commits
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
11 changes: 6 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
@@ -465,7 +465,7 @@ namespace ts {
let deferredGlobalImportMetaType: ObjectType;
let deferredGlobalExtractSymbol: Symbol;

let deferredNodes: Node[] | undefined;
let deferredNodes: Map<Node> | undefined;
const allPotentiallyUnusedIdentifiers = createMap<PotentiallyUnusedIdentifier[]>(); // 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(<ClassExpression>node);
break;
}
}
});
}

function checkSourceFile(node: SourceFile) {
@@ -26133,7 +26134,7 @@ namespace ts {
clear(potentialThisCollisions);
clear(potentialNewTargetCollisions);

deferredNodes = [];
deferredNodes = createMap<Node>();
forEach(node.statements, checkSourceElement);

checkDeferredNodes();
Original file line number Diff line number Diff line change
@@ -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'.
}
};

26 changes: 26 additions & 0 deletions tests/baselines/reference/checkSpecialPropertyAssignments.symbols
Original file line number Diff line number Diff line change
@@ -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))
}
};

31 changes: 31 additions & 0 deletions tests/baselines/reference/checkSpecialPropertyAssignments.types
Original file line number Diff line number Diff line change
@@ -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[]
}
};

14 changes: 14 additions & 0 deletions tests/cases/conformance/salsa/checkSpecialPropertyAssignments.ts
Original file line number Diff line number Diff line change
@@ -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;
}
};