@@ -226,6 +226,7 @@ type ReverseMappedTypeKey struct {
226
226
type IterationTypesKey struct {
227
227
typeId TypeId
228
228
use IterationUse
229
+ nodeId ast.NodeId
229
230
}
230
231
231
232
// FlowLoopKey
@@ -5881,26 +5882,21 @@ func (c *Checker) getIterationTypesOfIterable(t *Type, use IterationUse, errorNo
5881
5882
if IsTypeAny(t) {
5882
5883
return IterationTypes{c.anyType, c.anyType, c.anyType}
5883
5884
}
5884
- key := IterationTypesKey{typeId: t.id, use: use & IterationUseCacheFlags}
5885
- // If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
5886
- // In addition, we should not cache any new results for this call.
5887
- noCache := false
5888
- if cached, ok := c.iterationTypesCache[key]; ok {
5889
- if errorNode == nil || cached.hasTypes() {
5890
- return cached
5891
- }
5892
- noCache = true
5885
+ var nodeId ast.NodeId
5886
+ if errorNode != nil {
5887
+ nodeId = ast.GetNodeId(errorNode)
5893
5888
}
5894
- result := c.getIterationTypesOfIterableWorker(t , use, errorNode, noCache)
5895
- if !noCache {
5896
- c.iterationTypesCache[key] = result
5889
+ key := IterationTypesKey{typeId: t.id , use: use&IterationUseCacheFlags, nodeId: nodeId}
5890
+ if cached, ok := c.iterationTypesCache[key]; ok {
5891
+ return cached
5897
5892
}
5893
+ result := c.getIterationTypesOfIterableWorker(t, use, errorNode)
5898
5894
return result
5899
5895
}
5900
5896
5901
- func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node, noCache bool ) IterationTypes {
5897
+ func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node) IterationTypes {
5902
5898
if t.flags&TypeFlagsUnion != 0 {
5903
- return c.combineIterationTypes(core.Map(t.Types(), func(t *Type) IterationTypes { return c.getIterationTypesOfIterableWorker(t, use, errorNode, noCache ) }))
5899
+ return c.combineIterationTypes(core.Map(t.Types(), func(t *Type) IterationTypes { return c.getIterationTypesOfIterableWorker(t, use, errorNode) }))
5904
5900
}
5905
5901
if use&IterationUseAllowsAsyncIterablesFlag != 0 {
5906
5902
iterationTypes := c.getIterationTypesOfIterableFast(t, c.asyncIterationTypesResolver)
0 commit comments