Skip to content

Fix array casts as list type#1959

Merged
ondrejmirtes merged 8 commits intophpstan:1.9.xfrom
rajyan:fix-list-types
Nov 4, 2022
Merged

Fix array casts as list type#1959
ondrejmirtes merged 8 commits intophpstan:1.9.xfrom
rajyan:fix-list-types

Conversation

@rajyan
Copy link
Copy Markdown
Contributor

@rajyan rajyan commented Nov 3, 2022

fixes array cast of types as list

@rajyan
Copy link
Copy Markdown
Contributor Author

rajyan commented Nov 3, 2022

For numeric, falsy, non-empty string, it's weird that the casted type is array<0, non-empty-string> (which is wrong). I think there is another underlying bug.

@rajyan
Copy link
Copy Markdown
Contributor Author

rajyan commented Nov 3, 2022

ok, it was not wrong, but intersection of two constant arrays narrowed to array type was the cause.

@rajyan
Copy link
Copy Markdown
Contributor Author

rajyan commented Nov 3, 2022

Very weird only failing on windows...

@rajyan
Copy link
Copy Markdown
Contributor Author

rajyan commented Nov 3, 2022

solved
the namespace was wrong

@rajyan rajyan marked this pull request as ready for review November 3, 2022 22:58
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@rajyan rajyan changed the title Fix list types Fix array casts as as list type Nov 3, 2022
@rajyan rajyan marked this pull request as draft November 3, 2022 23:04
@rajyan
Copy link
Copy Markdown
Contributor Author

rajyan commented Nov 3, 2022

Noticed that failing tests of composer is caused from my previous PR 8b456c5
I'll look into it.

@rajyan
Copy link
Copy Markdown
Contributor Author

rajyan commented Nov 3, 2022

I think the composer failure is caused because of this composer update
https://github.com/phpstan/phpstan/blob/c1ea106f9a101643d4e224c0917cef4eb0c1f60c/.github/workflows/integration-tests.yml#L127
The CI of composer is failing right now while migrating to PHPstan 1.9.0
https://github.com/composer/composer

I'm not sure why the composer integration test is running composer update.

@rajyan rajyan marked this pull request as ready for review November 3, 2022 23:32
@phpstan-bot
Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@rajyan rajyan changed the title Fix array casts as as list type Fix array casts as list type Nov 4, 2022
foo((array) (fn () => 'closure'));
foo((array) $nonEmptyString);
foo((array) $nonFalsyString);
foo((array) $numericString);
Copy link
Copy Markdown
Contributor

@staabm staabm Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test code should be wrapped into a method or function (no top level code, when possible as it would get executed when running the testsuite)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to define parameter types as @param rather than @var.

@rajyan
Copy link
Copy Markdown
Contributor Author

rajyan commented Nov 4, 2022

fixed the tests and moved to CallMethodsRule
Playground result to show that the test is failing without this PR.
https://phpstan.org/r/e7dcb950-2cdc-4a07-9d4d-e89b58856b48

@rajyan
Copy link
Copy Markdown
Contributor Author

rajyan commented Nov 4, 2022

I was taking literal-string wrong.
Fixed the test and the correct playground result is this
https://phpstan.org/r/75e6f175-55e5-42aa-9cfc-64343c705af8

@ondrejmirtes ondrejmirtes merged commit d0c971e into phpstan:1.9.x Nov 4, 2022
@ondrejmirtes
Copy link
Copy Markdown
Member

Thank you!

@rajyan rajyan deleted the fix-list-types branch November 4, 2022 12:22
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.

4 participants