I had weird errors at work. I tried to run Psalm against almost all the project for the first time and I had this error:
Exception
Uncaught UnexpectedValueException: Expecting c:\users\Username\documents\phpstormprojects\project_name\req\v0.0.0\_global\objets\internes\customer_name.class.php:4544:237529:-:closure to have storage in C:\Users\Username\Documents\PhpstormProjects\project_name\req\v0.0.0\_GLOBAL\objets\internes\customer_name.class.php in C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Codebase.php:642
Stack trace:
#0 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ClosureAnalyzer.php(24): Psalm\Codebase->getClosureStorage('C:\\Users\\Username...', 'c:\\users\\Username...')
#1 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer.php(462): Psalm\Internal\Analyzer\ClosureAnalyzer->__construct(Object(PhpParser\Node\Expr\Closure), Object(Psalm\Internal\Analyzer\StatementsAnalyzer))
#2 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Expression\CallAnalyzer.php(542): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\Closure), Object(Psalm\Context))
#3 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Expression\Call\FunctionCallAnalyzer.php(421): Psalm\Internal\Analyzer\Statements\Expression\CallAnalyzer::checkFunctionArguments(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Array, Array, 'uasort', Object(Psalm\Context))
#4 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer.php(442): Psalm\Internal\Analyzer\Statements\Expression\Call\FunctionCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context))
#5 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(683): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context), false, NULL, true)
#6 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer.php(738): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context))
#7 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer.php(345): Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer::analyzeIfBlock(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Internal\Scope\IfScope), Object(Psalm\Context), Object(Psalm\Context), Object(Psalm\Context), Array)
#8 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(359): Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context))
#9 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FunctionLikeAnalyzer.php(526): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), Object(Psalm\Context), true)
#10 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ClassAnalyzer.php(1650): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Internal\Provider\NodeDataProvider), Object(Psalm\Context))
#11 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ClassAnalyzer.php(813): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod(Object(PhpParser\Node\Stmt\ClassMethod), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Internal\Analyzer\ClassAnalyzer), Object(Psalm\Context), Object(Psalm\Context))
#12 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FileAnalyzer.php(201): Psalm\Internal\Analyzer\ClassAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Context))
#13 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(335): Psalm\Internal\Analyzer\FileAnalyzer->analyze(NULL)
#14 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(567): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}(7004, 'C:\\Users\\Username...')
#15 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(258): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1)
#16 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ProjectAnalyzer.php(528): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer),1, false)
#17 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\psalm.php(553): Psalm\Internal\Analyzer\ProjectAnalyzer->check('C:\\Users\\Username...', false)
#18 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\psalm(2): require_once('C:\\Users\\Username...')
#19 {main}
(Psalm 3.8.3@389af1bfc739bfdff3f9e3dc7bd6499aee51a831 crashed due to an uncaught Throwable)
I looked at the code, unfortunately, this particular file is thousands of line long and I couldn't reproduce on a smaller sample. I then tried to ignore this whole file but I had an other error which seems related:
Exception
Uncaught InvalidArgumentException: Could not get class storage for customer_name in C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Provider\ClassLikeStorageProvider.php:47
Stack trace:
#0 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\ClassLikes.php(1447): Psalm\Internal\Provider\ClassLikeStorageProvider->get('customer_name')
#1 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Type\Reconciler.php(493): Psalm\Internal\Codebase\ClassLikes->getConstantForClass('customer_name', '$t_params_code_...', 4, NULL)
#2 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Type\Reconciler.php(229): Psalm\Type\Reconciler::getValueForKey(Object(Psalm\Codebase), 'customer_name::$t_para...', Array, Object(Psalm\CodeLocation), false, false)
#3 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer.php(256): Psalm\Type\Reconciler::reconcileKeyedTypes(Array, Array, Array, Array, Array, Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Array, true, Object(Psalm\CodeLocation))
#4 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(359): Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context))
#5 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Block\LoopAnalyzer.php(195): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context))
#6 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Block\ForeachAnalyzer.php(308): Psalm\Internal\Analyzer\Statements\Block\LoopAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Array, Array, Array, Object(Psalm\Internal\Scope\LoopScope), Object(Psalm\Context))
#7 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(371): Psalm\Internal\Analyzer\Statements\Block\ForeachAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Foreach_), Object(Psalm\Context))
#8 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer.php(1553): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context))
#9 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer.php(382): Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer::analyzeElseBlock(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\Else_), Object(Psalm\Internal\Scope\IfScope), Object(Psalm\Context), Object(Psalm\Context))
#10 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\StatementsAnalyzer.php(359): Psalm\Internal\Analyzer\Statements\Block\IfAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Stmt\If_), Object(Psalm\Context))
#11 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FunctionLikeAnalyzer.php(526): Psalm\Internal\Analyzer\StatementsAnalyzer->analyze(Array, Object(Psalm\Context), Object(Psalm\Context), true)
#12 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ClassAnalyzer.php(1650): Psalm\Internal\Analyzer\FunctionLikeAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Internal\Provider\NodeDataProvider), Object(Psalm\Context))
#13 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ClassAnalyzer.php(813): Psalm\Internal\Analyzer\ClassAnalyzer->analyzeClassMethod(Object(PhpParser\Node\Stmt\ClassMethod), Object(Psalm\Storage\ClassLikeStorage), Object(Psalm\Internal\Analyzer\ClassAnalyzer), Object(Psalm\Context), Object(Psalm\Context))
#14 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\FileAnalyzer.php(201): Psalm\Internal\Analyzer\ClassAnalyzer->analyze(Object(Psalm\Context), Object(Psalm\Context))
#15 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(335): Psalm\Internal\Analyzer\FileAnalyzer->analyze(NULL)
#16 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(567): Psalm\Internal\Codebase\Analyzer->Psalm\Internal\Codebase\{closure}(7269, 'C:\\Users\\Username...')
#17 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Codebase\Analyzer.php(258): Psalm\Internal\Codebase\Analyzer->doAnalysis(Object(Psalm\Internal\Analyzer\ProjectAnalyzer), 1)
#18 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\Psalm\Internal\Analyzer\ProjectAnalyzer.php(528): Psalm\Internal\Codebase\Analyzer->analyzeFiles(Object(Psalm\Internal\Analyzer\ProjectAnalyzer),1, false)
#19 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\src\psalm.php(553): Psalm\Internal\Analyzer\ProjectAnalyzer->check('C:\\Users\\Username...', false)
#20 C:\Users\Username\Documents\PhpstormProjects\project_name\vendor\vimeo\psalm\psalm(2): require_once('C:\\Users\\Username...')
#21 {main}
(Psalm 3.8.3@389af1bfc739bfdff3f9e3dc7bd6499aee51a831 crashed due to an uncaught Throwable)
The "customer_name" string comes back on the second error so I guess those errors are related.
I don't have a code example to produce (as I said, I couldn't reproduce and the highlighted code was just a standard closure).
Do you have any hints what could cause that kind of errors or things I could try to fix it?
(Note: I couldn't make a lot of tests, our project is quite massive and it takes almost half an hour before failing...)
more info needed