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
Internal error when using trait in abstract class with abstract __invoke() method. #4210
Comments
I found these snippets: https://psalm.dev/r/15fea19e9a<?php
function testFunc(callable $func) : void
{
$func();
}
trait TestTrait
{
abstract public function __invoke() : void;
public function apply() : void
{
testFunc($this);
}
}
abstract class TestClass {
use TestTrait;
}
|
For the moment the workaround seems to be repeating the abstract declaration of |
I found these snippets: https://psalm.dev/r/14ad4df24d<?php
function testFunc(callable $func) : void
{
$func();
}
trait TestTrait
{
abstract public function __invoke() : void;
public function apply() : void
{
testFunc($this);
}
}
abstract class TestClass
{
use TestTrait;
abstract public function __invoke() : void;
}
|
The internal error also appear if the abstract |
I found these snippets: https://psalm.dev/r/ed9e55f42a<?php
function testFunc(callable $func) : void
{
$func();
}
trait TestTrait
{
public function apply() : void
{
testFunc($this);
}
}
interface TestInterface
{
public function __invoke() : void;
}
abstract class TestClass implements TestInterface
{
use TestTrait;
}
|
muglug
added a commit
that referenced
this issue
Oct 7, 2020
danog
pushed a commit
to danog/psalm
that referenced
this issue
Jan 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This started with 3.15 (3.14.2 seems to still work well).
https://psalm.dev/r/15fea19e9a
The following conditions seem to be crucial:
function testFunc(callable $func) : void
- the parameter is declared as callable (either by type hinting or in docblock),abstract public function __invoke() : void;
- this declaration is present inTestTrait
,abstract public function __invoke() : void;
- this declaration is not present inTestClass
testFunc($this);
- this invocation is present within the trait'sapply()
method,abstract class TestClass { // ...
- the class must be declared as abstractuse TestTrait
- trait is used inTestClass
,If any of the above is not meet, then there is no internal error.
The text was updated successfully, but these errors were encountered: