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

Iterating over type with static #4267

Closed
ondrejmirtes opened this issue Dec 20, 2020 · 8 comments
Closed

Iterating over type with static #4267

ondrejmirtes opened this issue Dec 20, 2020 · 8 comments
Labels
Milestone

Comments

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Dec 20, 2020

Bug report

Originally reported: #4220

Both versions with generics and without generics should work.

It might just be a matter of modifying ObjectType::getIterableValueType(), to resolve the StaticType (similar to this https://github.com/phpstan/phpstan-src/blob/19bf582aa3c0e0809446a17399d17d17ab40297c/src/Analyser/MutatingScope.php#L4515-L4526).

Code snippet that reproduces the problem

Expected output

Correctly resolved $h to HelloWorld.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Dec 20, 2020
@mvorisek
Copy link
Contributor

more details on how to fix: #4220 (reply in thread)

@mvorisek
Copy link
Contributor

@ondrejmirtes I was able to fix it with this patch: https://github.com/mvorisek/atk4-hintable-mirror/blob/1.1.5/patch-phpstan-static-type-issue-4267.php

here is the patch in an action: https://github.com/atk4/data/pull/821/files

fix for src/Type/ObjectType.php seems more or less legit, fix for is what I proposed in phpstan/phpstan-src#414, please help with fixing this issue officially, I do not have a deep knowledge of phpstan internals

@ondrejmirtes
Copy link
Member Author

please help with fixing this issue officially

I filed this issue among hundreds other bug reports and feature requests, please adjust your expectations accordingly. It can take some time before I think of this as a priority. I consider this https://phpstan.org/r/9829582c-f3a5-48e4-ae43-d43d709e8282 a very good workaround.

@mvorisek
Copy link
Contributor

Model in atk4/data is a base model for all user's models used by thousands of users worldwide. As per average project there are a lot of different Model classes, this workaround is not possible.

The phpstan patch I released fixes this issue, but of course it is a fragile/short term solution.

@phpstan-bot
Copy link
Contributor

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

@@ @@
-24: Access to an undefined property Model::$x.
+No errors

@phpstan-bot
Copy link
Contributor

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

@@ @@
- 3: Class Model implements generic interface IteratorAggregate but does not specify its types: TKey, TValue
-21: Access to an undefined property Model::$x.
+ 3: Class Model implements generic interface IteratorAggregate but does not specify its types: TKey, TValue
Full report
Line Error
3 Class Model implements generic interface IteratorAggregate but does not specify its types: TKey, TValue

@ondrejmirtes
Copy link
Member Author

This frikking thing took me 3 days to figure out... phpstan/phpstan-src#474

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

Successfully merging a pull request may close this issue.

3 participants