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

@phpstan-assert tags are not correctly implicitly inherited #10037

Closed
ondrejmirtes opened this issue Oct 20, 2023 · 8 comments · Fixed by phpstan/phpstan-src#2909
Closed

@phpstan-assert tags are not correctly implicitly inherited #10037

ondrejmirtes opened this issue Oct 20, 2023 · 8 comments · Fixed by phpstan/phpstan-src#2909
Labels
Milestone

Comments

@ondrejmirtes
Copy link
Member

Bug report

See the example. It works only if the assert tag is repeated in PostFetcher.

Code snippet that reproduces the problem

https://phpstan.org/r/fb8735dc-026d-40ea-a724-c2e7eef04a9a

Expected output

Correct type in the truthy if branch.

Did PHPStan help you today? Did it make you happy in any way?

No response

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Oct 20, 2023
@phpstan-bot
Copy link
Contributor

@ondrejmirtes After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
-PHP 8.1 – 8.3 (4 errors)
+PHP 8.2 – 8.3 (4 errors)
 ==========
 
+44: Dumped type: Identifier
+46: Dumped type: T of Identifier (class Fetcher, parameter)
+47: Parameter #1 $identifier of method PostFetcher::fetch() expects PostIdentifier, T of Identifier given.
+49: Parameter #1 $identifier of method PostFetcher::fetch() expects PostIdentifier, Identifier given.
+
+PHP 8.1 (5 errors)
+==========
+
+20: Readonly classes are supported only on PHP 8.2 and later.
 44: Dumped type: Identifier
 46: Dumped type: T of Identifier (class Fetcher, parameter)
 47: Parameter #1 $identifier of method PostFetcher::fetch() expects PostIdentifier, T of Identifier given.
Full report

PHP 8.2 – 8.3 (4 errors)

Line Error
44 Dumped type: Identifier
46 Dumped type: T of Identifier (class Fetcher, parameter)
47 Parameter #1 $identifier of method PostFetcher::fetch() expects PostIdentifier, T of Identifier given.
49 Parameter #1 $identifier of method PostFetcher::fetch() expects PostIdentifier, Identifier given.

PHP 8.1 (5 errors)

Line Error
20 Readonly classes are supported only on PHP 8.2 and later.
44 Dumped type: Identifier
46 Dumped type: T of Identifier (class Fetcher, parameter)
47 Parameter #1 $identifier of method PostFetcher::fetch() expects PostIdentifier, T of Identifier given.
49 Parameter #1 $identifier of method PostFetcher::fetch() expects PostIdentifier, Identifier given.

PHP 7.2 – 8.0 (1 error)

Line Error
20 Syntax error, unexpected T_STRING, expecting T_ABSTRACT or T_FINAL or T_READONLY or T_CLASS on line 20

@ondrejmirtes
Copy link
Member Author

@RobertMe
Copy link

RobertMe commented Feb 1, 2024

And another confirmed similar issue: #10520

How easy would an easy fix be :) Something I can help out with / any hint where to start? (searching for assert-if-true in the codebase and see where I end up? :P)

@ondrejmirtes
Copy link
Member Author

I guess it's a missing self::resolveTemplateTypeInTag call in ResolvedPhpDocBlock::mergeAssertTags() but I could be wrong.

When fixing issues like this, it's worth it to go through all similar methods to see if the bug is also in a place that was not yet reported (while you have the right context in your head).

@ondrejmirtes
Copy link
Member Author

Possible bugs in mergeThrowsTags, mergeSelfOutTypeTags. Needs to be verified first.

@RobertMe
Copy link

RobertMe commented Feb 1, 2024

I guess it's a missing self::resolveTemplateTypeInTag call in ResolvedPhpDocBlock::mergeAssertTags() but I could be wrong.

Just quickly going over the code it indeed isn't called, I'll find out whether it's actually missing (or intended like this) when trying to fix it. Will check the others (throws, self-out as you mentioned, and possible others) as well in that case.

I'll see what I can come up with during the weekend

RobertMe added a commit to RobertMe/phpstan-src that referenced this issue Feb 10, 2024
@ondrejmirtes
Copy link
Member Author

Fixed: phpstan/phpstan-src#2909

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants