Skip to content

Conversation

@enumag
Copy link
Contributor

@enumag enumag commented Sep 2, 2020

Copy link
Member

Choose a reason for hiding this comment

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

This isn't what I suggested. Keep the test but try to fix ConstantArrayType::generalize() implementation instead. It just needs to do TypeCombinator::intersect(new ArrayType(...), new NonEmptyArrayType()); instead on the last line.

Copy link
Contributor Author

@enumag enumag Sep 3, 2020

Choose a reason for hiding this comment

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

When looking more into it I realized that your suggestion is actually incorrect. I added a test which would break in your case:

function dummy4(?DateTimeInterface $date): void { assertType('DateTimeInterface|false', min(array_filter([$date]))); }
Copy link
Member

Choose a reason for hiding this comment

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

My suggestion is necessary, non empty constant array needs to be generalized into a non empty general array. But it might not be sufficient to fix this bug and something else needs to be done in the extension too.

Copy link
Contributor Author

@enumag enumag Sep 3, 2020

Choose a reason for hiding this comment

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

Alright. Check this commit please if it is what you want.

It will most likely break the ArrayFilterFunctionReturnTypeReturnTypeExtension again so I'll look into it. Just wanna know if the ConstantArrayType fix is correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It broke a bunch of other tests though...

@enumag
Copy link
Contributor Author

enumag commented Sep 2, 2020 via email

@enumag enumag force-pushed the feature/fix-array-filter branch from 0dad8f7 to d1f038e Compare September 3, 2020 06:15
@enumag enumag marked this pull request as ready for review September 3, 2020 06:18
@enumag enumag force-pushed the feature/fix-array-filter branch from fc00482 to f26514d Compare September 3, 2020 06:44
@ondrejmirtes
Copy link
Member

Yeah, so the actual fix in ConstantArrayType::generalize() surfaces some other bugs that have to be looked into. Unfortunately I don't have time to look into this now so if no one is able to fix this on their own to get to a green build, it will have to wait until it's a priority for me. I want to look into the backlog of Easy fixes before 1.0 comes out.

@enumag
Copy link
Contributor Author

enumag commented Sep 3, 2020

In that case would you consider merging my changes to ArrayFilterFunctionReturnTypeReturnTypeExtension without fixing the ->generalize() here?

@enumag
Copy link
Contributor Author

enumag commented Sep 4, 2020

I tried but... I'm afraid that I can't fix the ConstantArrayType::generalize() method and make everything green. I'm fairly confident that my first commit alone is fine though. And it does fix the issue I want to fix.

@enumag
Copy link
Contributor Author

enumag commented Sep 4, 2020

Simply put, the ArrayFilterFunctionReturnTypeReturnTypeExtension needs to use the old implementation of generalize() because the ->isIterableAtLeastOnce() result is not reliable and the extension needs to decide it on it's own. But when I do change the generalize() method I'm unsure how to fix the extension.

@ondrejmirtes
Copy link
Member

Superseded by: d67dae3

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

Labels

None yet

3 participants