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 4.23 and 4.24 crashes on enum const used in php 8.1 Annotations #8242

Closed
4s3man opened this issue Jul 10, 2022 · 4 comments · Fixed by #8694
Closed

Psalm 4.23 and 4.24 crashes on enum const used in php 8.1 Annotations #8242

4s3man opened this issue Jul 10, 2022 · 4 comments · Fixed by #8694

Comments

@4s3man
Copy link

4s3man commented Jul 10, 2022

bin/psalm
Target PHP version: 8.1 (inferred from composer.json)
Scanning files...
Uncaught RuntimeException: Failed to infer case value for COMPANY_NOT_EXISTS in /app/vendor/vimeo/psalm/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php:1360
Stack trace:
#0 /app/vendor/vimeo/psalm/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php(713): Psalm\Internal\PhpVisitor\Reflector\ClassLikeNodeScanner->visitEnumDeclaration(Object(PhpParser\Node\Stmt\EnumCase), Object(Psalm\Storage\ClassLikeStorage), 'App\Model\Confi...')
#1 /app/vendor/vimeo/psalm/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php(185): Psalm\Internal\PhpVisitor\Reflector\ClassLikeNodeScanner->start(Object(PhpParser\Node\Stmt\Enum_))
#2 /app/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(200): Psalm\Internal\PhpVisitor\ReflectorVisitor->enterNode(Object(PhpParser\Node\Stmt\Enum_))
#3 /app/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(114): PhpParser\NodeTraverser->traverseArray(Array)
#4 /app/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(223): PhpParser\NodeTraverser->traverseNode(Object(PhpParser\Node\Stmt\Namespace_))
#5 /app/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php(91): PhpParser\NodeTraverser->traverseArray(Array)
#6 /app/vendor/vimeo/psalm/src/Psalm/Internal/Scanner/FileScanner.php(88): PhpParser\NodeTraverser->traverse(Array)
#7 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Scanner.php(589): Psalm\Internal\Scanner\FileScanner->scan(Object(Psalm\Codebase), Object(Psalm\Storage\FileStorage), false, Object(Psalm\Progress\DefaultProgress))
#8 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Scanner.php(339): Psalm\Internal\Codebase\Scanner->scanFile('/app/src/Model/...', Array, false)
#9 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Scanner.php(459): Psalm\Internal\Codebase\Scanner->Psalm\Internal\Codebase{closure}(2, '/app/src/Model/...')
#10 /app/vendor/vimeo/psalm/src/Psalm/Internal/Codebase/Scanner.php(303): Psalm\Internal\Codebase\Scanner->scanFilePaths(1)
#11 /app/vendor/vimeo/psalm/src/Psalm/Codebase.php(518): Psalm\Internal\Codebase\Scanner->scanFiles(Object(Psalm\Internal\Codebase\ClassLikes), 7)
#12 /app/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php(662): Psalm\Codebase->scanFiles(7)
#13 /app/vendor/vimeo/psalm/src/Psalm/Internal/Cli/Psalm.php(373): Psalm\Internal\Analyzer\ProjectAnalyzer->check('/app/', true)
#14 /app/vendor/vimeo/psalm/psalm(7): Psalm\Internal\Cli\Psalm::run(Array)
#15 /app/bin/psalm(120): include('/app/vendor/vim...')
#16 {main}
(Psalm 4.23.0@f1fe6ff483bf325c803df9f510d09a03fd796f88 crashed due to an uncaught Throwable)
Script bin/psalm handling the psalm event returned with error code 1

How to reproduce problem:

  1. In symfony App, create enum with public const like this:
@4s3man
Copy link
Author

4s3man commented Jul 10, 2022

Hey @4s3man, can you reproduce the issue on https://psalm.dev ?

no it requires php8.1. annotations

@AndrolGenhald
Copy link
Collaborator

AndrolGenhald commented Jul 11, 2022

How to reproduce problem:

  1. In symfony App, create enum with public const like this:

I think you missed a bit there. Can you create a minimal reproduction repository that we can clone and easily reproduce?

@mparafiniuk
Copy link

mparafiniuk commented Jul 11, 2022

This error doesn't have anything to do with annotations/attributes. It's simple case like this: https://psalm.dev/r/6c585f12dd which is correct code in php8.1 https://3v4l.org/tImgH#v8.1.8

I guess its due to null passed here as 6th argument:

  $case_type = SimpleTypeInferer::infer(
      $this->codebase,
      new NodeDataProvider(),
      $stmt->expr,
      $this->aliases,
      $this->file_scanner,
      null, // enum case value expressions cannot reference constants
      $fq_classlike_name
  );

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/6c585f12dd
<?php

enum Test: string
{
    public const ENUM_VALUE = 'ENUM_VALUE';

    case ENUM = self::ENUM_VALUE;
}
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php: Failed to infer case value for ENUM

@weirdan weirdan self-assigned this Nov 10, 2022
weirdan added a commit to weirdan/psalm that referenced this issue Nov 10, 2022
weirdan added a commit to weirdan/psalm that referenced this issue Nov 10, 2022
weirdan added a commit that referenced this issue Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants