Skip to content

Commit 82f927f

Browse files
authored
Fix stack overflow in circular assignment declaration (#34543)
* Fix stack overflow in circular assignment declaration It also needs to have multiple assignments so that it has a ValueModule flag. Fixes #33006 * remove errant comment * Remove other possible circularity * Restore fallback with additional condition
1 parent 9ff9c41 commit 82f927f

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7270,7 +7270,7 @@ namespace ts {
72707270
// Handle variable, parameter or property
72717271
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
72727272
// Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty`
7273-
if (symbol.flags & SymbolFlags.ValueModule) {
7273+
if (symbol.flags & SymbolFlags.ValueModule && !(symbol.flags & SymbolFlags.Assignment)) {
72747274
return getTypeOfFuncClassEnumModule(symbol);
72757275
}
72767276
return reportCircularityError(symbol);
@@ -7340,7 +7340,7 @@ namespace ts {
73407340

73417341
if (!popTypeResolution()) {
73427342
// Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty`
7343-
if (symbol.flags & SymbolFlags.ValueModule) {
7343+
if (symbol.flags & SymbolFlags.ValueModule && !(symbol.flags & SymbolFlags.Assignment)) {
73447344
return getTypeOfFuncClassEnumModule(symbol);
73457345
}
73467346
return reportCircularityError(symbol);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/salsa/circularMultipleAssignmentDeclaration.js ===
2+
ns.next = ns.next || { shared: {} };
3+
>ns.next : Symbol(ns.next, Decl(circularMultipleAssignmentDeclaration.js, 0, 0), Decl(circularMultipleAssignmentDeclaration.js, 1, 3))
4+
>ns : Symbol(ns, Decl(circularMultipleAssignmentDeclaration.js, 0, 0), Decl(circularMultipleAssignmentDeclaration.js, 0, 36))
5+
>next : Symbol(ns.next, Decl(circularMultipleAssignmentDeclaration.js, 0, 0), Decl(circularMultipleAssignmentDeclaration.js, 1, 3))
6+
>ns.next : Symbol(ns.next, Decl(circularMultipleAssignmentDeclaration.js, 0, 0), Decl(circularMultipleAssignmentDeclaration.js, 1, 3))
7+
>ns : Symbol(ns, Decl(circularMultipleAssignmentDeclaration.js, 0, 0), Decl(circularMultipleAssignmentDeclaration.js, 0, 36))
8+
>next : Symbol(ns.next, Decl(circularMultipleAssignmentDeclaration.js, 0, 0), Decl(circularMultipleAssignmentDeclaration.js, 1, 3))
9+
>shared : Symbol(shared, Decl(circularMultipleAssignmentDeclaration.js, 0, 22))
10+
11+
ns.next.shared.mymethod = {};
12+
>ns.next : Symbol(ns.next, Decl(circularMultipleAssignmentDeclaration.js, 0, 0), Decl(circularMultipleAssignmentDeclaration.js, 1, 3))
13+
>ns : Symbol(ns, Decl(circularMultipleAssignmentDeclaration.js, 0, 0), Decl(circularMultipleAssignmentDeclaration.js, 0, 36))
14+
>next : Symbol(ns.next, Decl(circularMultipleAssignmentDeclaration.js, 0, 0), Decl(circularMultipleAssignmentDeclaration.js, 1, 3))
15+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/conformance/salsa/circularMultipleAssignmentDeclaration.js ===
2+
ns.next = ns.next || { shared: {} };
3+
>ns.next = ns.next || { shared: {} } : any
4+
>ns.next : any
5+
>ns : typeof ns
6+
>next : any
7+
>ns.next || { shared: {} } : any
8+
>ns.next : any
9+
>ns : typeof ns
10+
>next : any
11+
>{ shared: {} } : { shared: {}; }
12+
>shared : {}
13+
>{} : {}
14+
15+
ns.next.shared.mymethod = {};
16+
>ns.next.shared.mymethod = {} : {}
17+
>ns.next.shared.mymethod : any
18+
>ns.next.shared : any
19+
>ns.next : any
20+
>ns : typeof ns
21+
>next : any
22+
>shared : any
23+
>mymethod : any
24+
>{} : {}
25+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @filename:circularMultipleAssignmentDeclaration.js
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @noEmit: true
5+
ns.next = ns.next || { shared: {} };
6+
ns.next.shared.mymethod = {};

0 commit comments

Comments
 (0)