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

Template type not supporting string|null although it works fine #5305

Closed
janedbal opened this issue Jul 14, 2021 · 8 comments
Closed

Template type not supporting string|null although it works fine #5305

janedbal opened this issue Jul 14, 2021 · 8 comments
Labels
Milestone

Comments

@janedbal
Copy link
Contributor

Bug report

Getting PHPDoc tag @template T for method HelloWorld::normalize() with bound type null is not supported. in following snippet, but the functionality seems working, is that just invalid error?

Code snippet that reproduces the problem

https://phpstan.org/r/04528bd4-6738-4b6e-b9f3-4756ce08c3f7

Expected output

No error on line 19

@ondrejmirtes ondrejmirtes added this to the Generics milestone Jul 14, 2021
@phpstan-bot
Copy link
Contributor

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

@@ @@
- 7: Parameter #1 $foo of method HelloWorld::strict() expects string, null given.
-19: PHPDoc tag @template T for method HelloWorld::normalize() with bound type null is not supported.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md
Full report
Line Error
-1 Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40Run PHPStan with --debug option and post the stack trace to:https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md

@phpstan-bot
Copy link
Contributor

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

@@ @@
- 7: Parameter #1 $foo of method HelloWorld::strict() expects string, null given.
+19: Method HelloWorld::normalize() should return T of string|null but return statement is missing.
 19: PHPDoc tag @template T for method HelloWorld::normalize() with bound type null is not supported.
Full report
Line Error
19 `Method HelloWorld::normalize() should return T of string
19 PHPDoc tag @template T for method HelloWorld::normalize() with bound type null is not supported.

@phpstan-bot
Copy link
Contributor

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

@@ @@
- 7: Parameter #1 $foo of method HelloWorld::strict() expects string, null given.
-19: PHPDoc tag @template T for method HelloWorld::normalize() with bound type null is not supported.
+ 7: Parameter #1 $foo of method HelloWorld::strict() expects string, null given.
Full report
Line Error
7 Parameter #1 $foo of method HelloWorld::strict() expects string, null given.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@1d8b2eb

@ZebulanStanphill
Copy link
Contributor

@ondrejmirtes Is it? It looks like passing null to the method is still considered invalid.

@ondrejmirtes
Copy link
Member

$this->normalize(null) resolves to null which looks correct to me.

@ZebulanStanphill
Copy link
Contributor

@ondrejmirtes Oh, you're right. I misread the code snippet. 👍

@github-actions
Copy link

github-actions bot commented Mar 3, 2022

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 3, 2022
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

4 participants