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

Array created with values should be marked as non-empty #5382

Closed
b1rdex opened this issue Jul 27, 2021 · 18 comments
Closed

Array created with values should be marked as non-empty #5382

b1rdex opened this issue Jul 27, 2021 · 18 comments
Labels
Milestone

Comments

@b1rdex
Copy link
Contributor

b1rdex commented Jul 27, 2021

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/61906720-950c-49db-889b-07e62d97761f

Expected output

No errors

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

Sure!

@b1rdex b1rdex changed the title Array created with values should be marked non-empty Array created with values should be marked as non-empty Jul 27, 2021
@ondrejmirtes
Copy link
Member

I think this is specific to handling of the ?? operator.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Jul 27, 2021
@b1rdex
Copy link
Contributor Author

b1rdex commented Jul 27, 2021

All the ternaries are affected: https://phpstan.org/r/55ae7f8b-313e-4b7a-a155-72c4bf71ac70

@AlexandruGG
Copy link

AlexandruGG commented Jul 28, 2021

Even before any ternary the type is not inferred correctly, the intersection with nonEmpty is missing:

https://phpstan.org/r/d1174fdc-7213-4b11-8049-860d47e67fa7

@ondrejmirtes
Copy link
Member

That's not the reason, ConstantArrayType knows if it's empty or not by itself, it doesn't need the &nonEmpty part.

@AlexandruGG
Copy link

That's not the reason, ConstantArrayType knows if it's empty or not by itself, it doesn't need the &nonEmpty part.

You're right, removing the null coalescing shows both of them working: https://phpstan.org/r/a805b504-a3bb-40ca-8a28-e32b97dd2d9e

@phpstan-bot
Copy link
Contributor

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

@@ @@
-15: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
+-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

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

@@ @@
-19: Dumped type: array<int, stdClass>&nonEmpty
-20: Dumped type: array(stdClass)
-23: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
+-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

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

@@ @@
-13: Constructor of class HelloWorld has an unused parameter $providers.
-19: Dumped type: array<int, stdClass>&nonEmpty
-20: Dumped type: array(stdClass)
+-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

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

@@ @@
-15: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
+15: Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
Full report
Line Error
15 Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-15: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
-19: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
-23: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
-30: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
+15: Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
+19: Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
+23: Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
+30: Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
Full report
Line Error
15 Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
19 Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
23 Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
30 Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-19: Dumped type: array<int, stdClass>&nonEmpty
+19: Dumped type: non-empty-array<int, stdClass>
 20: Dumped type: array(stdClass)
-23: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
+23: Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
Full report
Line Error
19 Dumped type: non-empty-array<int, stdClass>
20 Dumped type: array(stdClass)
23 Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.

@phpstan-bot
Copy link
Contributor

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

@@ @@
 13: Constructor of class HelloWorld has an unused parameter $providers.
-19: Dumped type: array<int, stdClass>&nonEmpty
+19: Dumped type: non-empty-array<int, stdClass>
 20: Dumped type: array(stdClass)
Full report
Line Error
13 Constructor of class HelloWorld has an unused parameter $providers.
19 Dumped type: non-empty-array<int, stdClass>
20 Dumped type: array(stdClass)

@phpstan-bot
Copy link
Contributor

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

@@ @@
-19: Dumped type: array<int, stdClass>&nonEmpty
-20: Dumped type: array(stdClass)
-23: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
+19: Dumped type: non-empty-array<int, stdClass>
+20: Dumped type: array{stdClass}
+23: Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.
Full report
Line Error
19 Dumped type: non-empty-array<int, stdClass>
20 Dumped type: array{stdClass}
23 Property HelloWorld::$providers (non-empty-array<int, stdClass>) does not accept array<int, stdClass>.

@phpstan-bot
Copy link
Contributor

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

@@ @@
 13: Constructor of class HelloWorld has an unused parameter $providers.
-19: Dumped type: array<int, stdClass>&nonEmpty
-20: Dumped type: array(stdClass)
+19: Dumped type: non-empty-array<int, stdClass>
+20: Dumped type: array{stdClass}
Full report
Line Error
13 Constructor of class HelloWorld has an unused parameter $providers.
19 Dumped type: non-empty-array<int, stdClass>
20 Dumped type: array{stdClass}

@phpstan-bot
Copy link
Contributor

@b1rdex After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
-15: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
+No errors

@phpstan-bot
Copy link
Contributor

@b1rdex After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
-15: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
-19: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
-23: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
-30: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
+No errors

@phpstan-bot
Copy link
Contributor

@AlexandruGG After the latest commit in 1.6.x, PHPStan now reports different result with your code snippet:

@@ @@
-19: Dumped type: array<int, stdClass>&nonEmpty
-20: Dumped type: array(stdClass)
-23: Property HelloWorld::$providers (array<int, stdClass>&nonEmpty) does not accept array<int, stdClass>.
+19: Dumped type: non-empty-array<int, stdClass>
+20: Dumped type: array{stdClass}
Full report
Line Error
19 Dumped type: non-empty-array<int, stdClass>
20 Dumped type: array{stdClass}

@github-actions
Copy link

github-actions bot commented May 4, 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 May 4, 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