Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psalm crashing during analysis #11363

Closed
cseufert opened this issue Mar 19, 2025 · 8 comments
Closed

Psalm crashing during analysis #11363

cseufert opened this issue Mar 19, 2025 · 8 comments

Comments

@cseufert
Copy link

Getting a crash during analysis running both psalm and psalter. Not sure what to try, running with -d opcache.enable=0 doesnt help either, I am running in PHP 8.4.4

Uncaught Amp\Parallel\Worker\TaskFailureException: UnexpectedValueException thrown in context with message "This should not happen" and code "0" in /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ReturnTypeProvider/FilterInputReturnTypeProvider.php:247
Stack trace in context:
#0 /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Provider/FunctionReturnTypeProvider.php(162): Psalm\Internal\Provider\ReturnTypeProvider\FilterInputReturnTypeProvider::getFunctionReturnType(Object(Psalm\Plugin\EventHandler\Event\FunctionReturnTypeProviderEvent))
#1 /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php(103): Psalm\Internal\Provider\FunctionReturnTypeProvider->getReturnType(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), "filter_input", Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context), Object(Psalm\CodeLocation))
#2 /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php(246): Psalm\Internal\Analyzer\Statements\Expression\Call\FunctionCallReturnTypeFetcher::fetch(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(Psalm\Codebase), Object(PhpParser\Node\Expr\FuncCall), Object(PhpParser\Node\Name), "filter_input", true, false, null, Object(Psalm\Type\Atomic\TCallable), Object(Psalm\Internal\Type\TemplateResult), Object(Psalm\Context))
...
Copy link

Hey @cseufert, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.

@cseufert
Copy link
Author

I have run with --threads=0 and still crashes, with slightly different error:

Uncaught UnexpectedValueException: This should not happen in /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Provider/ReturnTypeProvider/FilterInputReturnTypeProvider.php:247
Stack trace:
#0 /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Provider/FunctionReturnTypeProvider.php(162): Psalm\Internal\Provider\ReturnTypeProvider\FilterInputReturnTypeProvider::getFunctionReturnType(Object(Psalm\Plugin\EventHandler\Event\FunctionReturnTypeProviderEvent))
#1 /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php(103): Psalm\Internal\Provider\FunctionReturnTypeProvider->getReturnType(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), 'filter_input', Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context), Object(Psalm\CodeLocation))
#2 /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php(246): Psalm\Internal\Analyzer\Statements\Expression\Call\FunctionCallReturnTypeFetcher::fetch(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(Psalm\Codebase), Object(PhpParser\Node\Expr\FuncCall), Object(PhpParser\Node\Name), 'filter_input', true, false, NULL, Object(Psalm\Type\Atomic\TCallable), Object(Psalm\Internal\Type\TemplateResult), Object(Psalm\Context))
#3 /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(318): Psalm\Internal\Analyzer\Statements\Expression\Call\FunctionCallAnalyzer::analyze(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context), Object(Psalm\Internal\Type\TemplateResult))
#4 /home/chris/code/moddengine-stable/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php(92): Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::handleExpression(Object(Psalm\Internal\Analyzer\StatementsAnalyzer), Object(PhpParser\Node\Expr\FuncCall), Object(Psalm\Context), false, NULL, NULL, NULL, false)
...

@cseufert
Copy link
Author

No idea why this example crashes psalm, but only when run in the context of my project

https://psalm.dev/r/15a8065a34

Copy link

I found these snippets:

https://psalm.dev/r/15a8065a34
<?php

namespace Modd\Engine\Plugins\ServerDate;

use Psr\Http\Message\ResponseInterface;

class HttpApi
{
  /**
   * @url /
   * @return bool|string
   * @throws \Exception
   */
  static function serverDate(ResponseInterface $response)
  {
    $now = round(1000 * microtime(true));
    $res = $response->withHeader('Content-Type', 'application/json');
    if (filter_input(INPUT_GET, 'time')) {
      $res->getBody()->write($now);
      return $res;
    }
    $out = file_get_contents(
      ME_DIR .
        implode(DIRECTORY_SEPARATOR, [
          '',
          'plugin',
          'moddeng',
          'serverdate',
          'js',
          'serverdate.js',
        ]),
    );
    $out .= "($now);";
    $res->getBody()->write($out);

    return $res;
  }
}
Psalm output (using commit 354b4d4):

ERROR: InvalidOperand - 16:18 - Cannot process ints and floats in strict binary operands mode, please cast explicitly

ERROR: RiskyTruthyFalsyComparison - 18:9 - Operand of type false|null|string contains type string, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead.

ERROR: InvalidScalarArgument - 19:30 - Argument 1 of Psr\Http\Message\StreamInterface::write expects string, but float provided

ERROR: InvalidReturnStatement - 20:14 - The inferred type 'Psr\Http\Message\ResponseInterface&static' does not match the declared return type 'bool|string' for Modd\Engine\Plugins\ServerDate\HttpApi::serverDate

ERROR: UndefinedConstant - 23:7 - Const ME_DIR is not defined, consider enabling the allConstantsGlobal config option if scanning legacy codebases

ERROR: InvalidReturnStatement - 36:12 - The inferred type 'Psr\Http\Message\ResponseInterface&static' does not match the declared return type 'bool|string' for Modd\Engine\Plugins\ServerDate\HttpApi::serverDate

ERROR: InvalidReturnType - 11:14 - The declared return type 'bool|string' for Modd\Engine\Plugins\ServerDate\HttpApi::serverDate is incorrect, got 'Psr\Http\Message\ResponseInterface&static'

danog added a commit that referenced this issue Mar 20, 2025
danog added a commit that referenced this issue Mar 20, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Hotfix #11363
@danog
Copy link
Collaborator

danog commented Mar 20, 2025

Fixed in the next release.

@danog danog closed this as completed Mar 20, 2025
@wannevancamp
Copy link

I'm unsure if it's related, but the latest versions (since 6.9.1 ?) recently started crashing in the pipeline.

Running on PHP 8.2.28, Psalm 6.9.4@e052de4275fb6cdbfedfef1d883a7e90732ea609.
JIT acceleration: ON
JIT compilation in progress... Uncaught ParseError: syntax error, unexpected identifier "OLD", expecting "=" in /opt/atlassian/pipelines/agent/build/vendor/sebastian/diff/src/Differ.php:33
Stack trace:
#0 /opt/atlassian/pipelines/agent/build/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/opt/atlassian/...')
#1 [internal function]: Composer\Autoload\ClassLoader->loadClass('SebastianBergma...')
#2 /opt/atlassian/pipelines/agent/build/vendor/vimeo/psalm/src/Psalm/Internal/Preloader.php(27): class_exists('SebastianBergma...')
#3 /opt/atlassian/pipelines/agent/build/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(1025): Psalm\Internal\Preloader::preload(Object(Psalm\Progress\LongProgress), true)
#4 /opt/atlassian/pipelines/agent/build/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(287): Psalm\Internal\Cli\Psalm::restart(Array, 1, 1, Object(Psalm\Progress\LongProgress))
#5 /opt/atlassian/pipelines/agent/build/vendor/vimeo/psalm/psalm(9): Psalm\Internal\Cli\Psalm::run(Array)
#6 /opt/atlassian/pipelines/agent/build/vendor/bin/psalm(119): include('/opt/atlassian/...')
#7 {main}
(Psalm 6.9.4@e052de4275fb6cdbfedfef1d883a7e90732ea609 crashed due to an uncaught Throwable)
To skip commit checks, add -n or --no-verify flag to commit command

@danog
Copy link
Collaborator

danog commented Mar 21, 2025

That seems like an issue with your composer packages, you've likely installed sebastian/diff v7, which is not compatible with php 8.2.

@wannevancamp
Copy link

Thanks, you're right. That was the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants