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

First-class callable #6989

Closed
userqq opened this issue Nov 25, 2021 · 8 comments
Closed

First-class callable #6989

userqq opened this issue Nov 25, 2021 · 8 comments

Comments

@userqq
Copy link

userqq commented Nov 25, 2021

Hi, I'm trying to get works psalm with php8.1 syntax, but getting error
Uncaught AssertionError: assert(!$this->isFirstClassCallable()) in /app/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/CallLike.php:36
when trying to inspect following line

array_map($this->handle(...), $message->parameters['messages']->value);

When I trying to run the snippet https://psalm.dev/r/399d485cde , https://psalm.dev/check responds with 500 error:

<b>Warning</b>:  Undefined property: PhpParser\Node\VariadicPlaceholder::$name in <b>/var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php</b> on line <b>118</b><br />
<br />
<b>Warning</b>:  Undefined property: PhpParser\Node\VariadicPlaceholder::$value in <b>/var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php</b> on line <b>177</b><br />
<br />
<b>Warning</b>:  Undefined property: PhpParser\Node\VariadicPlaceholder::$value in <b>/var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php</b> on line <b>178</b><br />
<br />
<b>Warning</b>:  Undefined property: PhpParser\Node\VariadicPlaceholder::$value in <b>/var/www/vhosts/psalm.dev/httpdocs/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php</b> on line <b>200</b><br />
{"error":{"message":"\/vendor\/vimeo\/psalm\/src\/Psalm\/Internal\/Analyzer\/Statements\/ExpressionAnalyzer.php: Psalm\\Internal\\Analyzer\\Statements\\ExpressionAnalyzer::analyze(): Argument #2 ($stmt) must be of type PhpParser\\Node\\Expr, null given, called in \/vendor\/vimeo\/psalm\/src\/Psalm\/Internal\/Analyzer\/Statements\/Expression\/Call\/ArgumentsAnalyzer.php on line 200","line_from":35,"type":"psalm_error"}}
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/399d485cde
<?php

class Foo
{
	public function bar(): array
    {
        return $this->map($this->baz(...), [1, 2, 3]);
    }

    private function baz(int $val): int
    {
        return $val * 2;
    }

    private function map(callable $callback, array $val): array
    {
        $result = [];
        foreach ($val as $key => $value) {
            $result[$key] = $callback($value);
        }

        return $result;
    }
}

var_dump((new Foo)->bar());
Psalm encountered an internal error:

/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php: Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer::analyze(): Argument #2 ($stmt) must be of type PhpParser\Node\Expr, null given, called in /vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php on line 200

@weirdan
Copy link
Collaborator

weirdan commented Nov 25, 2021

Can you try parsing the source file with vendor/bin/php-parse? If that fails it needs to be reported upstream: https://github.com/nikic/PHP-Parser/issues

@orklah
Copy link
Collaborator

orklah commented Nov 25, 2021

It's not a PHP-Parser issue, it's indirectly due to #6628

in PHP-Parser 4.13, the argument list (for a MethodCall in this case) is not longer a list of Args due to PHP support for first class callable. It can now be a VariadicPlaceholder also.

In #6628, I replaced every use of MethodCall::args (and others) by MethodCall::getArgs() in order to fallback to a method that returns the same list of Args as before.

However, PHP-Parser does an assert on MethodCall::args in order to check that it's not a first class callable to be able to make sure it only return Args.

The effect of that is that Psalm doesn't have support for first class callable (it would have failed to parse in PHP-Parser 4.12 and now it fails on the assertion)

This makes this issue very related to #6412, if not a duplicate

@FractalizeR
Copy link

Any news here? Stumbled over the same problem

@orklah
Copy link
Collaborator

orklah commented Dec 20, 2021

Actually, this should have been closed by #7113. @FractalizeR if you could make sure your use case work in latest master, it would help checking everything works. Please open a new issue if you encounter difficulties

@orklah orklah closed this as completed Dec 20, 2021
@FractalizeR
Copy link

Latest master (pointing composer to dev-master branch) didn't work. The error is still:

psalm: Target PHP version: 8.1 (inferred from composer.json)
Scanning files...
Analyzing files...
Uncaught AssertionError: assert(!$this->isFirstClassCallable()) in <...>/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/CallLike.php:36
Stack trace:
#0 <...>/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/CallLike.php(36): assert(false, 'assert(!$this->...')
#1 <...>/vendor/vimeo/psalm/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeCollector.php(358): PhpParser\Node\Expr\CallLike->getArgs()

@orklah
Copy link
Collaborator

orklah commented Dec 20, 2021

@FractalizeR can you please open a new issue?

@userqq
Copy link
Author

userqq commented Dec 21, 2021

@FractalizeR can you please open a new issue?

@orklah I did - #7196

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

No branches or pull requests

4 participants