Skip to content

Conversation

herndlm
Copy link
Contributor

@herndlm herndlm commented Nov 10, 2024

equivalent of #3617 but for foreach and polluteScopeWithAlwaysIterableForeach set to false.

not sure yet if there's a better way of dealing with the keyVar/valueVar variable expression checks..

don't know yet what this might be fixing..

@herndlm herndlm marked this pull request as draft November 10, 2024 13:49
@ondrejmirtes
Copy link
Member

I don't get it. What kind of bug is there in the foreach that needs fixing?

@herndlm
Copy link
Contributor Author

herndlm commented Nov 10, 2024

Setting something inside it that does not exist in scope already basically. Weird edge case, but the same as with for.

@herndlm
Copy link
Contributor Author

herndlm commented Nov 10, 2024

But it indeed doesn't look like this was even reported. Not sure if it's worth it then.


assertType('int<0, 1>', $c);
assertNativeType('int', $c);
assertVariableCertainty(TrinaryLogic::createYes(), $c);
Copy link
Member

Choose a reason for hiding this comment

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

This should not be yes but maybe. That's the point of polluteScopeWithAlwaysIterableForeach: false.

Please if for loop currently behaves like that then please fix the behaviour too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, the docs just talk about variables set in the loop init statements or the key and value variables. If so, my previous PR basically needs to be reverted and the issue it fixed was by design? :)

I can do this in the evening btw.

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, sorry about that phpstan/phpstan#9550 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries. Should I open a PR for all those tests only? In case they add value, otherwise I don't mind of course.

Copy link
Member

Choose a reason for hiding this comment

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

It's fine, I think it's well tested :)

@herndlm herndlm closed this Nov 10, 2024
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.

2 participants