-
Notifications
You must be signed in to change notification settings - Fork 542
Add support for PHP 8.5 #[\NoDiscard]
#4253
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
Add support for PHP 8.5 #[\NoDiscard]
#4253
Conversation
Wasn't able to figure out instance methods or static methods, I'll work on those separately later |
0b700c1
to
24db3f7
Compare
PHP 8.5 linting failure is unrelated, caused by yours truly in php/php-src@c416191 // php/php-src#19154 |
This is a wrong approach. We don't need a new rule but instead:
|
Per the docs https://phpstan.org/developing-extensions/backward-compatibility-promise
so can this be added to
FunctionCallParametersCheck doesn't include
Is this necessary? The
Is that necessary? That means a whole other rule for something that PHP would complain about at compile time anyway |
d3dc3d4
to
131caa6
Compare
Yes, some interfaces cannot be extended. If you try that you get an error: https://phpstan.org/r/847a20b4-ce41-4763-b7f4-aa088ea30bca
I'm sorry, I was mistaken. I had these lines in mind ( phpstan-src/src/Rules/FunctionCallParametersCheck.php Lines 275 to 284 in 8bb2a20
Call to pure functions without using their result is covered by these rules:
But I think we first should try to report this in FunctionCallParametersCheck.
The user already expresses their intention with
Yes. PHPStan users expect this to be reported. We should report all the situations from the "Constraints" section in the RFC (https://wiki.php.net/rfc/marking_return_value_as_important). |
I couldn't figure out using the scope, so I added a visitor to indicate method calls that use
What I mean is, is this necessary for this patch? Errors about when the attribute is applied are different from errors about when the methods with the attribute are called |
@DanielEScherzer My process for adding support for new PHP features is that I read the whole RFC and I update PHPStan with everything that should be added about the feature. If you don't do that, then I'd have to keep in mind to do it myself. |
Another important thing from the RFC:
Another rule checking the |
Sorry, tried to rename the branch but didn't realize that that closes the PR :( |
Okay, I have
|
#[\NoDiscard]
on functions#[\NoDiscard]
@ondrejmirtes my understanding is that this is awaiting review, is there something else I should do? (Don't want to nag, just want to make sure you aren't waiting for me to do something while I'm waiting for you or another reviewer) |
Please wait for the next review, I'm working through my queue 😊 |
Okay, just wanted to make sure you were not waiting for something from me, take your time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is starting to get in a good shape 👍
I'm missing checking whether #[NoDiscard]
is above a void-returning function/method. FunctionDefinitionCheck would be a natural place for that.
public function hasNoDiscardAttribute(): TrinaryLogic | ||
{ | ||
foreach ($this->attributes as $attrib) { | ||
if ($attrib->getName() === 'NoDiscard') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dtto
This is probably worth creating a NoDiscardHelper
class
src/Parser/VoidCastVisitor.php
Outdated
public function enterNode(Node $node): ?Node | ||
{ | ||
if ($node instanceof Void_) { | ||
$this->pendingVoidCast = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get the need for this visitor, can you elaborate please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to figure out how to, within a rule, associate a node for a method call with the previous node to check if the previous node was a (void)
cast, so I added a visitor to do that instead
Hello, I'd like to ask: Are you going to finish this or should I take over? Thank you. |
4fa0ef0
to
3cf3684
Compare
done, only thing not tested is a void-returning property hook since property hooks do not support type hints
I'll finish it up There are some CI failures, but they seem unrelated to this? |
b1be3f5
to
702201d
Compare
I removed the visitor and no tests are failing. Can you try breaking the test suite now with some code that the visitor should have covered? |
FYI I'm taking over and finishing this PR. Just let me know about the visitor, thanks 😊 |
e50db5d
to
277be5d
Compare
Seems complete now. Feel free to check out my commits what additional things I added 😊 |
phpunit is too slow locally
2406024
to
5db8f0d
Compare
Thank you! |
No description provided.