Navigation Menu

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

Immutable unions #8627

Merged
merged 90 commits into from Nov 4, 2022
Merged

Immutable unions #8627

merged 90 commits into from Nov 4, 2022

Conversation

danog
Copy link
Collaborator

@danog danog commented Oct 27, 2022

This PR introduces fully immutable union types and some work towards immutable storages (I realized that while that's a good thing to have, the only thing we really need to avoid mutability bugs are immutable unions).

Marking this as draft due to the ~30 psalm issues I have to fix, plus a very nasty (set of) side-effects related to parent_nodes, which I'm currently trying to fix.

Basically, the trick here is to fix https://psalm.dev/r/eb9860a6c5, which is caused by src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php:428 dropping all already-asserted info about $function_call_arg->value->items[0] and children, because src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/InstancePropertyFetchAnalyzer.php:429 re-assigns some types after AtomicPropertyFetchAnalyzer::processTaints.

Technically, the behavior of IfElseAnalyzer is correct: when changing parent nodes ie due to a variable re-assignment (first part of the psalm.dev example), all known assertions about the variable and children should be dropped.
However, in this specific example in InstancePropertyFetchAnalyzer, originally the re-assignment is propagated to parent contexts, and I haven't figured out yet the proper way of replicating this.

new TIntRange(0, 8),
new TNonEmptyList(Type::getInt()),
]),
'name' => $str,
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this change be included in this PR? Feels like it should be added for 4.x?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I suppose this could be backported as well, just wanted to include it in this PR since I also introduced memoization for global types and wanted to avoid merge conflicts in this section of the VariableFetchAnalyzer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Though it would have to be changed a bit, here I re-use the string type for example, that can cause nasty issues in 4.x where unions aren't immutable

@danog danog marked this pull request as ready for review October 31, 2022 12:39
@orklah
Copy link
Collaborator

orklah commented Oct 31, 2022

Seems like phpunit plugin broke :(

@danog
Copy link
Collaborator Author

danog commented Oct 31, 2022

Yep, this PR requires the other PR I sent to the phpunit plugin

@orklah
Copy link
Collaborator

orklah commented Oct 31, 2022

Can you check there? We'll need to make a dedicated release for the phpunit plugin on version 5

@danog
Copy link
Collaborator Author

danog commented Oct 31, 2022

+, done!

@danog
Copy link
Collaborator Author

danog commented Nov 1, 2022

Also fixed the parent_nodes issues.

@orklah
Copy link
Collaborator

orklah commented Nov 1, 2022

Not sure why, but composer install 0.16.1 of psalm's phpunit plugin, not 0.18.0...

@danog
Copy link
Collaborator Author

danog commented Nov 1, 2022

That's because in semver 0.x versions are treated as major, only 0.x.y versions are treated as minor.
I suggest pulling 0.18.0 and re-tagging 1.17.1, since there are no breaking changes.

@danog
Copy link
Collaborator Author

danog commented Nov 1, 2022

Nevermind, already updated ;)

@orklah
Copy link
Collaborator

orklah commented Nov 2, 2022

0.18.1 doesn't seem to resolve the issue here

@danog
Copy link
Collaborator Author

danog commented Nov 2, 2022

Yeah, maybe it'll work after merging on master?
Or maybe I should add a version constant somewhere...

@orklah
Copy link
Collaborator

orklah commented Nov 3, 2022

Oh! New error :)

@danog
Copy link
Collaborator Author

danog commented Nov 3, 2022

Yeah, sorry about this, psalm/psalm-plugin-phpunit#126 works for sure, just tested :)

@orklah
Copy link
Collaborator

orklah commented Nov 4, 2022

I think this could be merged now. Can you cleanup some commits (or should I squish everything?). Please try to make sure every baseline addition is legit and it should be ok

@danog
Copy link
Collaborator Author

danog commented Nov 4, 2022

You can squash-merge, afaik all commit messages are retained when squash-merging, and yes I made sure all the baselined issues are pre-existing psalm bugs :P

@orklah orklah added the release:internal The PR will be included in 'Internal changes' section of the release notes label Nov 4, 2022
@orklah orklah merged commit d0be59e into vimeo:master Nov 4, 2022
@orklah
Copy link
Collaborator

orklah commented Nov 4, 2022

Thanks a lot!

@danog
Copy link
Collaborator Author

danog commented Nov 4, 2022

YAY :D
Just fixed up #8395, that should be good to merge too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:internal The PR will be included in 'Internal changes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants