Skip to content

Conversation

@dktapps
Copy link
Contributor

@dktapps dktapps commented Aug 31, 2020

this fixes phpstan/phpstan#3782.
I'm not sure if this may have any side effects, but I can't see any circumstances where it makes sense to reassign an object as an array on array dim fetch.

this fixes phpstan/phpstan#3782.
I'm not sure if this may have any side effects, but I can't see any circumstances where it makes sense to reassign an object as an array on array dim fetch.
this resulted in a change of behaviour in one of the tests, which I think is OK because this bug fix happens to kill another bird with the same stone: repeated access to illegal offsets on strings now report **all** illegal accesses instead of just the first one.
@dktapps
Copy link
Contributor Author

dktapps commented Aug 31, 2020

The latest commit caused a change in behaviour to the result of string offset accesses, which I believe is acceptable because the old behaviour was causing some errors not to be reported, like the one missing from line 8 here: https://phpstan.org/r/801fa88f-87bb-49c3-8c6c-ea8b781fb950

this test is broken because of phpstan/phpstan#3803, because phpstan believes the string will never change in this scenario, which is wrong.
a non-benevolent union type key may or may not change a string, which is what we want for this test.
@dktapps dktapps changed the title NodeScopeResolver: do not reassign objects as arrays on ArrayDimFetch NodeScopeResolver: do not corrupt type info on invalid offset assignments Oct 3, 2020
@ondrejmirtes ondrejmirtes force-pushed the master branch 2 times, most recently from f54fd5f to eca550a Compare October 28, 2020 19:41
@dktapps
Copy link
Contributor Author

dktapps commented Nov 5, 2020

This is fixed for the object case, but the following array coercion is still not expected (and is fixed by this PR): https://phpstan.org/r/43b7a9c7-06cf-414c-ab58-63392fa4a357
https://3v4l.org/N9Aoe

@ondrejmirtes
Copy link
Member

This happens because $str after the first assignment becomes ErrorType.

@ondrejmirtes
Copy link
Member

The linked issue got fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array-access on object inside foreach not reported

2 participants