-
-
Notifications
You must be signed in to change notification settings - Fork 862
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
False positives on array access on iterable
property with PHPDoc type that allows it
#6243
Comments
The problem is that having:
leads to So that's what we need to solve here. |
phpstan/phpstan-src#891 solves that by keeping the PHPDoc type as-is. I had to change a few existing tests but that seemed legit to me. Are there use cases I am missing that would require a different fix? |
@julienfalque After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-13: Cannot access offset int on (ArrayAccess<int, string>&iterable<int, string>)|iterable<int, string>.
+13: Cannot access offset int on iterable<int, string>.
17: Cannot access an offset on iterable<int, string>. Full report
|
@ondrejmirtes After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
12: Dumped type: (ArrayAccess<int, string>&iterable<int, string>)|iterable<int, string>
-14: Cannot access offset int on (ArrayAccess<int, string>&iterable<int, string>)|iterable<int, string>.
+14: Cannot access offset int on iterable<int, string>.
18: Cannot access an offset on iterable<int, string>. Full report
|
@julienfalque After the latest commit in 1.7.x, PHPStan now reports different result with your code snippet: @@ @@
-13: Cannot access offset int on (ArrayAccess<int, string>&iterable<int, string>)|iterable<int, string>.
17: Cannot access an offset on iterable<int, string>. Full report
|
@ondrejmirtes After the latest commit in 1.7.x, PHPStan now reports different result with your code snippet: @@ @@
12: Dumped type: (ArrayAccess<int, string>&iterable<int, string>)|iterable<int, string>
-14: Cannot access offset int on (ArrayAccess<int, string>&iterable<int, string>)|iterable<int, string>.
18: Cannot access an offset on iterable<int, string>. Full report
|
@julienfalque After the latest push in 1.9.x, PHPStan now reports different result with your code snippet: @@ @@
-13: Cannot access offset int on (ArrayAccess<int, string>&iterable<int, string>)|iterable<int, string>.
-17: Cannot access an offset on iterable<int, string>.
+No errors |
@ondrejmirtes After the latest push in 1.9.x, PHPStan now reports different result with your code snippet: @@ @@
-12: Dumped type: (ArrayAccess<int, string>&iterable<int, string>)|iterable<int, string>
-14: Cannot access offset int on (ArrayAccess<int, string>&iterable<int, string>)|iterable<int, string>.
-18: Cannot access an offset on iterable<int, string>.
+12: Dumped type: list<string>|(ArrayAccess<int, string>&iterable<int, string>) Full report
|
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. |
Bug report
Given a property with native type
iterable
and PHPDoc type that allows array access, e.g.array
, reading or writing to this property using array access is reported as an error.Code snippet that reproduces the problem
PHPStan reports the following errors:
https://phpstan.org/r/42af72fd-760d-4132-8e1b-14449f2efe59
Expected output
No errors
The text was updated successfully, but these errors were encountered: