@@ -470,7 +470,6 @@ const (
470
470
IterationUseSpreadFlag IterationUse = 1 << 5
471
471
IterationUseDestructuringFlag IterationUse = 1 << 6
472
472
IterationUsePossiblyOutOfBounds IterationUse = 1 << 7
473
- IterationUseReportError IterationUse = 1 << 8
474
473
// Spread, Destructuring, Array element assignment
475
474
IterationUseElement = IterationUseAllowsSyncIterablesFlag
476
475
IterationUseSpread = IterationUseAllowsSyncIterablesFlag | IterationUseSpreadFlag
@@ -481,7 +480,7 @@ const (
481
480
IterationUseAsyncYieldStar = IterationUseAllowsSyncIterablesFlag | IterationUseAllowsAsyncIterablesFlag | IterationUseYieldStarFlag
482
481
IterationUseGeneratorReturnType = IterationUseAllowsSyncIterablesFlag
483
482
IterationUseAsyncGeneratorReturnType = IterationUseAllowsAsyncIterablesFlag
484
- IterationUseCacheFlags = IterationUseAllowsSyncIterablesFlag | IterationUseAllowsAsyncIterablesFlag | IterationUseForOfFlag | IterationUseReportError
483
+ IterationUseCacheFlags = IterationUseAllowsSyncIterablesFlag | IterationUseAllowsAsyncIterablesFlag | IterationUseForOfFlag
485
484
)
486
485
487
486
type IterationTypes struct {
@@ -5907,18 +5906,26 @@ func (c *Checker) getIterationTypesOfIterable(t *Type, use IterationUse, errorNo
5907
5906
if IsTypeAny(t) {
5908
5907
return IterationTypes{c.anyType, c.anyType, c.anyType}
5909
5908
}
5910
- key := IterationTypesKey{typeId: t.id, use: use&IterationUseCacheFlags | core.IfElse(errorNode != nil, IterationUseReportError, 0)}
5909
+ key := IterationTypesKey{typeId: t.id, use: use & IterationUseCacheFlags}
5910
+ // If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
5911
+ // In addition, we should not cache any new results for this call.
5912
+ noCache := false
5911
5913
if cached, ok := c.iterationTypesCache[key]; ok {
5912
- return cached
5914
+ if errorNode == nil || cached.hasTypes() {
5915
+ return cached
5916
+ }
5917
+ noCache = true
5918
+ }
5919
+ result := c.getIterationTypesOfIterableWorker(t, use, errorNode, noCache)
5920
+ if !noCache {
5921
+ c.iterationTypesCache[key] = result
5913
5922
}
5914
- result := c.getIterationTypesOfIterableWorker(t, use, errorNode)
5915
- c.iterationTypesCache[key] = result
5916
5923
return result
5917
5924
}
5918
5925
5919
- func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node) IterationTypes {
5926
+ func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node, noCache bool ) IterationTypes {
5920
5927
if t.flags&TypeFlagsUnion != 0 {
5921
- return c.combineIterationTypes(core.Map(t.Types(), func(t *Type) IterationTypes { return c.getIterationTypesOfIterableWorker(t, use, errorNode) }))
5928
+ return c.combineIterationTypes(core.Map(t.Types(), func(t *Type) IterationTypes { return c.getIterationTypesOfIterableWorker(t, use, errorNode, noCache ) }))
5922
5929
}
5923
5930
if use&IterationUseAllowsAsyncIterablesFlag != 0 {
5924
5931
iterationTypes := c.getIterationTypesOfIterableFast(t, c.asyncIterationTypesResolver)
0 commit comments