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

Values added to a nullable array aren't being type-checked #5804

Closed
gnarlyquack opened this issue Oct 18, 2021 · 3 comments
Closed

Values added to a nullable array aren't being type-checked #5804

gnarlyquack opened this issue Oct 18, 2021 · 3 comments
Labels
Milestone

Comments

@gnarlyquack
Copy link

Bug report

A property of type ?T[] can have any value assigned to it regardless of type without causing a type checking error.

Code snippet that reproduces the problem

https://phpstan.org/r/53a657a5-2847-4df6-84d1-7c209839dc6f

Expected output

Type errors on lines 13 and 15.

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

Yes, I'm using it in a current project.

@phpstan-bot
Copy link
Contributor

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

@@ @@
 12: Dumped type: array<int>|null
+13: Property Blah::$value (array<int>|null) does not accept array<int, string>.
 14: Dumped type: array<'hello'|int>
+15: Property Blah::$value (array<int>|null) does not accept array<int, Blah>.
 16: Dumped type: non-empty-array<'hello'|Blah|int>
Full report
Line Error
12 `Dumped type: array
13 `Property Blah::$value (array
14 `Dumped type: array<'hello'
15 `Property Blah::$value (array
16 `Dumped type: non-empty-array<'hello'

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@a2b318a

@github-actions
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 Feb 10, 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

3 participants