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-ignore-line do not work in chained setters #4250

Closed
Eimantas123 opened this issue Dec 18, 2020 · 12 comments
Closed

@phpstan-ignore-line do not work in chained setters #4250

Eimantas123 opened this issue Dec 18, 2020 · 12 comments
Labels

Comments

@Eimantas123
Copy link

Bug report

@phpstan-ignore-line do not work in setters when after ignored line there are more chained setters.

Code snippet that reproduces the problem

https://phpstan.org/r/5e363ac1-aebb-4ab6-8d8c-ed2f896ee088

Expected output

no error because we use // @phpstan-ignore-line

@Eimantas123 Eimantas123 changed the title @phpstan-ignore-line do not work in setters @phpstan-ignore-line do not work in chained setters Dec 18, 2020
@ondrejmirtes
Copy link
Member

Reported upstream: nikic/PHP-Parser#742

@mvorisek
Copy link
Contributor

mvorisek commented Dec 19, 2020

also, call to undefined method warning is rendered with wrong line: https://phpstan.org/r/b4bd2d03-7465-4b32-b731-895522112f57

quite important as chanined method calls are very often on separate lines

@digilist
Copy link

digilist commented Feb 4, 2021

I have a similar issue with function arguments:

function sayHello(DateTimeInterface $date): void {}

sayHello(
	new stdClass /* @phpstan-ignore-line */ 
);


sayHello(
	/* @phpstan-ignore-line */ new stdClass 
);

Only the second error is suppressed: https://phpstan.org/r/f19a1c5d-44eb-4f25-bb44-b5126fe29b0a

I would guess this is related?

@phpstan-bot
Copy link
Contributor

@Eimantas123 After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
+ 7: Property AwesomeFeature::$variable is never read, only written.
 35: Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string|null given.
Full report
Line Error
7 Property AwesomeFeature::$variable is never read, only written.
35 `Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string

@phpstan-bot
Copy link
Contributor

@mvorisek After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
+ 7: Property AwesomeFeature::$variable is never read, only written.
 34: Call to an undefined method AwesomeFeature::doSmthd().
 35: Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string|null given.
Full report
Line Error
7 Property AwesomeFeature::$variable is never read, only written.
34 Call to an undefined method AwesomeFeature::doSmthd().
35 `Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string

@phpstan-bot
Copy link
Contributor

@Eimantas123 After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
+ 7: Property AwesomeFeature::$variable is never read, only written.
 35: Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string|null given.
Full report
Line Error
7 Property AwesomeFeature::$variable is never read, only written.
35 `Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string

@phpstan-bot
Copy link
Contributor

@mvorisek After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
+ 7: Property AwesomeFeature::$variable is never read, only written.
 34: Call to an undefined method AwesomeFeature::doSmthd().
 35: Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string|null given.
Full report
Line Error
7 Property AwesomeFeature::$variable is never read, only written.
34 Call to an undefined method AwesomeFeature::doSmthd().
35 `Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string

@phpstan-bot
Copy link
Contributor

@Eimantas123 After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-35: Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string|null given.
+ 7: Property AwesomeFeature::$variable is never read, only written.
Full report
Line Error
7 Property AwesomeFeature::$variable is never read, only written.

@phpstan-bot
Copy link
Contributor

@mvorisek After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-34: Call to an undefined method AwesomeFeature::doSmthd().
-35: Parameter #1 $variable of method AwesomeFeature::setVariable() expects string, string|null given.
+ 7: Property AwesomeFeature::$variable is never read, only written.
+34: Call to an undefined method AwesomeFeature::doSmthd().
Full report
Line Error
7 Property AwesomeFeature::$variable is never read, only written.
34 Call to an undefined method AwesomeFeature::doSmthd().

@phpstan-bot
Copy link
Contributor

@digilist After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-6: Parameter #1 $date of function sayHello expects DateTimeInterface, stdClass given.
+No errors

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@9474696

@github-actions
Copy link

github-actions bot commented Dec 8, 2021

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 Dec 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants