Skip to content

Commit a5a4449

Browse files
committed
include nodeId in the cache key insead
1 parent c9f7b9e commit a5a4449

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

internal/checker/checker.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ type ReverseMappedTypeKey struct {
226226
type IterationTypesKey struct {
227227
typeId TypeId
228228
use IterationUse
229+
nodeId ast.NodeId
229230
}
230231

231232
// FlowLoopKey
@@ -5881,26 +5882,22 @@ func (c *Checker) getIterationTypesOfIterable(t *Type, use IterationUse, errorNo
58815882
if IsTypeAny(t) {
58825883
return IterationTypes{c.anyType, c.anyType, c.anyType}
58835884
}
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)
58935888
}
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
58975892
}
5893+
result := c.getIterationTypesOfIterableWorker(t, use, errorNode)
5894+
c.iterationTypesCache[key] = result
58985895
return result
58995896
}
59005897

5901-
func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node, noCache bool) IterationTypes {
5898+
func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node) IterationTypes {
59025899
if t.flags&TypeFlagsUnion != 0 {
5903-
return c.combineIterationTypes(core.Map(t.Types(), func(t *Type) IterationTypes { return c.getIterationTypesOfIterableWorker(t, use, errorNode, noCache) }))
5900+
return c.combineIterationTypes(core.Map(t.Types(), func(t *Type) IterationTypes { return c.getIterationTypesOfIterableWorker(t, use, errorNode) }))
59045901
}
59055902
if use&IterationUseAllowsAsyncIterablesFlag != 0 {
59065903
iterationTypes := c.getIterationTypesOfIterableFast(t, c.asyncIterationTypesResolver)

0 commit comments

Comments
 (0)