Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ type Checker struct {
reverseHomomorphicMappedCache map[ReverseMappedTypeKey]*Type
iterationTypesCache map[IterationTypesKey]IterationTypes
markerTypes collections.Set[*Type]
resolvingExplicitTypeOfSymbol collections.Set[*ast.Symbol]
undefinedSymbol *ast.Symbol
argumentsSymbol *ast.Symbol
requireSymbol *ast.Symbol
Expand Down
4 changes: 4 additions & 0 deletions internal/checker/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,10 @@ func (c *Checker) getTypeOfDottedName(node *ast.Node, diagnostic *ast.Diagnostic

func (c *Checker) getExplicitTypeOfSymbol(symbol *ast.Symbol, diagnostic *ast.Diagnostic) *Type {
symbol = c.resolveSymbol(symbol)
if !c.resolvingExplicitTypeOfSymbol.AddIfAbsent(symbol) {
return nil
}
defer c.resolvingExplicitTypeOfSymbol.Delete(symbol)
if symbol.Flags&(ast.SymbolFlagsFunction|ast.SymbolFlagsMethod|ast.SymbolFlagsClass|ast.SymbolFlagsValueModule) != 0 {
return c.getTypeOfSymbol(symbol)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
forOfSelfReferentialDottedName.ts(3,12): error TS7022: 'a' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
forOfSelfReferentialDottedName.ts(3,17): error TS2448: Block-scoped variable 'a' used before its declaration.


==== forOfSelfReferentialDottedName.ts (2 errors) ====
// A self-referential for-of iterable (`for (const a of a)`) plus a call and a
// later narrowing reference must not infinitely recurse in getExplicitTypeOfSymbol.
for (const a of a) {
~
!!! error TS7022: 'a' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
~
!!! error TS2448: Block-scoped variable 'a' used before its declaration.
!!! related TS2728 forOfSelfReferentialDottedName.ts:3:12: 'a' is declared here.
a();
a;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/forOfSelfReferentialDottedName.ts] ////

//// [forOfSelfReferentialDottedName.ts]
// A self-referential for-of iterable (`for (const a of a)`) plus a call and a
// later narrowing reference must not infinitely recurse in getExplicitTypeOfSymbol.
for (const a of a) {
a();
a;
}


//// [forOfSelfReferentialDottedName.js]
"use strict";
// A self-referential for-of iterable (`for (const a of a)`) plus a call and a
// later narrowing reference must not infinitely recurse in getExplicitTypeOfSymbol.
for (const a of a) {
a();
a;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/forOfSelfReferentialDottedName.ts] ////

=== forOfSelfReferentialDottedName.ts ===
// A self-referential for-of iterable (`for (const a of a)`) plus a call and a
// later narrowing reference must not infinitely recurse in getExplicitTypeOfSymbol.
for (const a of a) {
>a : Symbol(a, Decl(forOfSelfReferentialDottedName.ts, 2, 10))
>a : Symbol(a, Decl(forOfSelfReferentialDottedName.ts, 2, 10))

a();
>a : Symbol(a, Decl(forOfSelfReferentialDottedName.ts, 2, 10))

a;
>a : Symbol(a, Decl(forOfSelfReferentialDottedName.ts, 2, 10))
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/forOfSelfReferentialDottedName.ts] ////

=== forOfSelfReferentialDottedName.ts ===
// A self-referential for-of iterable (`for (const a of a)`) plus a call and a
// later narrowing reference must not infinitely recurse in getExplicitTypeOfSymbol.
for (const a of a) {
>a : any
>a : any

a();
>a() : any
>a : any

a;
>a : any
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// A self-referential for-of iterable (`for (const a of a)`) plus a call and a
// later narrowing reference must not infinitely recurse in getExplicitTypeOfSymbol.
for (const a of a) {
a();
a;
}