microsoft / pyright

Static Type Checker for Python
Other
13.43k stars 1.47k forks source link

"Error: Debug Failure. setIncompleteSubtype can be called only on a valid incomplete cache entry" #5355

Closed ottumm closed 1 year ago

ottumm commented 1 year ago

Describe the bug pyright 1.1.315 crashes from the command line with the below error when run against my codebase, while 1.1.314 runs successfully.

$ node --version
v18.16.0
An internal error occurred while type checking file "<redacted>": Error: Debug Failure. setIncompleteSubtype can be called only on a valid incomplete cache entry
    at setIncompleteSubtype (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:272:21)
    at forEach (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:956:33)
    at Array.forEach (<anonymous>)
    at getTypeFromLoopFlowNode (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:869:42)
    at getTypeFromFlowNode (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:585:32)
    at Object.getTypeFromCodeFlow (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:1073:20)
    at getFlowTypeOfReference (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18777:25)
    at getTypeOfName (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:4263:48)
    at getTypeOfExpression (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:967:30)
    at validateArgType (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:11244:40)
    at forEach (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:10685:31)
    at Array.forEach (<anonymous>)
    at validateFunctionArgumentTypes (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:10684:32)
    at validateFunctionArgumentTypesWithContext (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:10416:20)
    at validateFunctionArguments (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:10953:16)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:8835:48)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:3713:39)
    at A (node_modules/pyright/dist/pyright-internal/src/analyzer/typeUtils.ts:514:9)
    at expandSubtype (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:3706:13)
    at mapSubtypesExpandTypeVars (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:3737:13)
    at validateCallArguments (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:8764:26)
    at getTypeOfCall (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:7707:36)
    at getTypeOfExpression (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:982:30)
    at evaluateTypesForAssignmentStatement (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:14846:39)
    at evaluateTypesForStatement (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18595:25)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20218:17)
    at evaluateTypeForSubnode (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18709:9)
    at getInferredTypeOfDeclaration (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20217:32)
    at forEach (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20534:36)
    at Array.forEach (<anonymous>)
    at getEffectiveTypeOfSymbolForUsage (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20478:15)
    at getTypeOfName (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:4217:43)
    at getTypeOfExpression (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:967:30)
    at evaluateTypesForExpressionInContext (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18500:9)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:789:13)
    at evaluateTypeForSubnode (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18709:9)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:788:20)
    at i.getType [as timeOperation] (node_modules/pyright/dist/pyright-internal/src/common/timing.ts:40:20)
    at ae._validateConditionalIsBool (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:1662:45)
    at ae.visitWhile (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:878:14)
    at ae.visit (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:574:29)
    at ae.visitNode (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:933:21)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:915:37)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:307:19)
    at ae._walkStatementsAndReportUnreachable (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:2586:18)
    at ae.visitSuite (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:316:14)
    at ae.visit (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:544:29)
    at ae.visitNode (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:933:21)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:915:37)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:307:19)
    at ae.visitFunction (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:647:18)
    at ae.visit (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:442:29)
    at ae.visitNode (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:933:21)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:915:37)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:307:19)
    at ae._walkStatementsAndReportUnreachable (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:2586:18)
    at ae.check (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:286:14)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/sourceFile.ts:787:29)
    at i.timeOperation (node_modules/pyright/dist/pyright-internal/src/common/timing.ts:44:28)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/sourceFile.ts:778:45)
    at a.log (node_modules/pyright/dist/pyright-internal/src/common/logTracker.ts:45:20)
    at _e.check (node_modules/pyright/dist/pyright-internal/src/analyzer/sourceFile.ts:776:33)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/program.ts:1914:40)
    at a.log (node_modules/pyright/dist/pyright-internal/src/common/logTracker.ts:45:20)
Error performing analysis: Error: Debug Failure. setIncompleteSubtype can be called only on a valid incomplete cache entry
    at setIncompleteSubtype (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:272:21)
    at forEach (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:956:33)
    at Array.forEach (<anonymous>)
    at getTypeFromLoopFlowNode (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:869:42)
    at getTypeFromFlowNode (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:585:32)
    at Object.getTypeFromCodeFlow (node_modules/pyright/dist/pyright-internal/src/analyzer/codeFlowEngine.ts:1073:20)
    at getFlowTypeOfReference (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18777:25)
    at getTypeOfName (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:4263:48)
    at getTypeOfExpression (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:967:30)
    at validateArgType (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:11244:40)
    at forEach (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:10685:31)
    at Array.forEach (<anonymous>)
    at validateFunctionArgumentTypes (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:10684:32)
    at validateFunctionArgumentTypesWithContext (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:10416:20)
    at validateFunctionArguments (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:10953:16)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:8835:48)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:3713:39)
    at A (node_modules/pyright/dist/pyright-internal/src/analyzer/typeUtils.ts:514:9)
    at expandSubtype (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:3706:13)
    at mapSubtypesExpandTypeVars (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:3737:13)
    at validateCallArguments (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:8764:26)
    at getTypeOfCall (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:7707:36)
    at getTypeOfExpression (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:982:30)
    at evaluateTypesForAssignmentStatement (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:14846:39)
    at evaluateTypesForStatement (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18595:25)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20218:17)
    at evaluateTypeForSubnode (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18709:9)
    at getInferredTypeOfDeclaration (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20217:32)
    at forEach (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20534:36)
    at Array.forEach (<anonymous>)
    at getEffectiveTypeOfSymbolForUsage (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:20478:15)
    at getTypeOfName (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:4217:43)
    at getTypeOfExpression (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:967:30)
    at evaluateTypesForExpressionInContext (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18500:9)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:789:13)
    at evaluateTypeForSubnode (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:18709:9)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/typeEvaluator.ts:788:20)
    at i.getType [as timeOperation] (node_modules/pyright/dist/pyright-internal/src/common/timing.ts:40:20)
    at ae._validateConditionalIsBool (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:1662:45)
    at ae.visitWhile (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:878:14)
    at ae.visit (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:574:29)
    at ae.visitNode (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:933:21)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:915:37)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:307:19)
    at ae._walkStatementsAndReportUnreachable (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:2586:18)
    at ae.visitSuite (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:316:14)
    at ae.visit (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:544:29)
    at ae.visitNode (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:933:21)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:915:37)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:307:19)
    at ae.visitFunction (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:647:18)
    at ae.visit (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:442:29)
    at ae.visitNode (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:933:21)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/parseTreeWalker.ts:915:37)
    at ae.walk (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:307:19)
    at ae._walkStatementsAndReportUnreachable (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:2586:18)
    at ae.check (node_modules/pyright/dist/pyright-internal/src/analyzer/checker.ts:286:14)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/sourceFile.ts:787:29)
    at i.timeOperation (node_modules/pyright/dist/pyright-internal/src/common/timing.ts:44:28)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/sourceFile.ts:778:45)
    at a.log (node_modules/pyright/dist/pyright-internal/src/common/logTracker.ts:45:20)
    at _e.check (node_modules/pyright/dist/pyright-internal/src/analyzer/sourceFile.ts:776:33)
    at callback (node_modules/pyright/dist/pyright-internal/src/analyzer/program.ts:1914:40)
    at a.log (node_modules/pyright/dist/pyright-internal/src/common/logTracker.ts:45:20)
erictraut commented 1 year ago

Thanks for reporting this. Are you able to narrow down the problem to a particular piece of code? Is the code base publicly accessible?

ottumm commented 1 year ago

The codebase isn't public, but I'll see if I can narrow it down to a minimal reproducible case.

erictraut commented 1 year ago

Thanks, that would be really helpful. It will likely involve some doubly-nested (or deeper) for or while loop.

ottumm commented 1 year ago

I'm having a hard time building a minimal reproducible case. @erictraut is there any debug / verbose output I can enable to help you track this down?

erictraut commented 1 year ago

You could try the --verbose command-line option.

If you're using the language server version of pyright, you could try setting python.analysis.logLevel to "Trace" and python.analysis.logTypeEvaluationTime to true.

erictraut commented 1 year ago

I think I've fixed this problem. I still haven't been able to repro it, so I can't say for sure. Nor can I add a test case to test it. So if you find a repro case, that would still be helpful.

leoniewgnr commented 1 year ago

The pyright test fails currently for all of our PRs, this might be the same bug, but I'm not totally sure. But maybe this can help you to reproduce it? https://github.com/ourownstory/neural_prophet/pull/1356

erictraut commented 1 year ago

@leoniewgnr, thanks for the repro! That allowed me to understand the source of the bug and fix it.

leoniewgnr commented 1 year ago

So happy I could help!! Thanks for fixing it!😄

erictraut commented 1 year ago

This is addressed in pyright 1.1.316, which I just published. It will also be included in this week's insiders build of pylance.