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

Method __callStatic() breaks asserts on 5.23 #10807

Closed
SCIF opened this issue Mar 11, 2024 · 9 comments · Fixed by #10812
Closed

Method __callStatic() breaks asserts on 5.23 #10807

SCIF opened this issue Mar 11, 2024 · 9 comments · Fixed by #10812

Comments

@SCIF
Copy link
Contributor

SCIF commented Mar 11, 2024

https://psalm.dev/r/2a4ebd4d08

Copy link

I found these snippets:

https://psalm.dev/r/2a4ebd4d08
<?php

class A
{
    /** @psalm-assert non-empty-string $b */
    public static function notEmptyStrOnly(string $b): void
    {
        if ('' === $b) throw new \Exception('');
    }

    public static function __callStatic() {}
}

/** @return non-empty-string */
function returnNonEmpty(string $b): string
{
   A::notEmptyStrOnly($b);
   return $b;
}
Psalm output (using commit ef3b018):

INFO: LessSpecificReturnStatement - 18:11 - The type 'string' is more general than the declared return type 'non-empty-string' for returnNonEmpty

INFO: MoreSpecificReturnType - 14:13 - The declared return type 'non-empty-string' for returnNonEmpty is more specific than the inferred return type 'string'

@SCIF
Copy link
Contributor Author

SCIF commented Mar 11, 2024

I assume not only asserts affected, but much more, however, I haven't checked the damaged area.

@SCIF
Copy link
Contributor Author

SCIF commented Mar 11, 2024

Repro #10808

@SCIF
Copy link
Contributor Author

SCIF commented Mar 11, 2024

Reverting of #10704 has helped to pass the test. @issidorov please help if you have some time. :)

@antonioeatgoat

This comment was marked as off-topic.

This comment was marked as off-topic.

@weirdan

This comment was marked as off-topic.

@antonioeatgoat

This comment was marked as off-topic.

issidorov pushed a commit to issidorov/psalm that referenced this issue Mar 11, 2024
issidorov added a commit to issidorov/psalm that referenced this issue Mar 11, 2024
Resolved problem:
```
Psalm\Tests\AssertAnnotationTest::testAssertsAllongCallStaticMethodWork
Psalm\Exception\CodeException: LessSpecificReturnStatement
The type 'string' is more general than the declared return type 'non-empty-string' for returnNonEmpty
```
weirdan pushed a commit to issidorov/psalm that referenced this issue Mar 11, 2024
weirdan pushed a commit to issidorov/psalm that referenced this issue Mar 11, 2024
Resolved problem:
```
Psalm\Tests\AssertAnnotationTest::testAssertsAllongCallStaticMethodWork
Psalm\Exception\CodeException: LessSpecificReturnStatement
The type 'string' is more general than the declared return type 'non-empty-string' for returnNonEmpty
```
@weirdan
Copy link
Collaborator

weirdan commented Mar 11, 2024

Fixed in #10812

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

Successfully merging a pull request may close this issue.

3 participants