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-if-this-is crashes with enums #10979

Open
thomasvargiu opened this issue May 18, 2024 · 2 comments
Open

psalm-if-this-is crashes with enums #10979

thomasvargiu opened this issue May 18, 2024 · 2 comments

Comments

@thomasvargiu
Copy link
Contributor

https://psalm.dev/r/7bed033139

Uncaught RuntimeException: PHP Error: Undefined array key 0 in ./vendor/vimeo/psalm/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php:1171

if (count($mapped_type_atomic_types) > 1
|| !$mapped_type_atomic_types[0] instanceof TTemplateParam
) {
return $mapped_type;
}

Copy link

I found these snippets:

https://psalm.dev/r/7bed033139
<?php

enum EnumA: string {
    case FOO = 'foo';
    case BAR = 'bar';
}

/**
 * @template T of EnumA
 */
class C {
    /**
     * @var T
     */
    private $data;
    /**
     * @param T $data
     */
    public function __construct($data) {
        $this->data = $data;
    }
    /**
     * @psalm-if-this-is self<EnumA::FOO>
     * 
     * @return void
     */
    public function doSomething() {
        /** @var self<EnumA::FOO> $this */
        $this->data = EnumA::FOO;
        // just somthing random to show psalm crashes 
        rgahatrhagfhaf
    }
}
Psalm output (using commit 16b24bd):

ERROR: ParseError - 32:5 - Syntax error, unexpected '}' on line 32

ERROR: UndefinedConstant - 31:9 - Const rgahatrhagfhaf is not defined

@thomasvargiu
Copy link
Contributor Author

psalm-github-bot doesn't show the real output. Currently it crashes even in psalm.dev.

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

1 participant