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

Feature check redeclared readonly properties v2 #3049

Conversation

schlndh
Copy link
Contributor

@schlndh schlndh commented May 6, 2024

This is a relaxed (and reimplemented) version of the rule from: #3041 (comment)

Considering this example: https://phpstan.org/r/cf781e9e-cfdd-4aae-855d-ead64bf16afa - if (a subclass redeclares readonly property in promoted fashion OR assigns the redeclared readonly property) AND calls parent constructor AND parent constructor declares the readonly property in promoted fashion, then we should always report an error. This can be achieved with local analysis only, without performance impact. PHPStan should see that as duplicate assignment with existing rules in place. So MissingReadOnlyPropertyAssignRule should report "is already assigned" just by modifying the data that is fed into it.

Fixes phpstan/phpstan#8101
Fixes phpstan/phpstan#9863
Fixes phpstan/phpstan#9864

@ondrejmirtes ondrejmirtes changed the base branch from 1.10.x to 1.11.x May 6, 2024 13:01
@ondrejmirtes ondrejmirtes force-pushed the feature-checkRedeclaredReadonlyPropertiesV2 branch from 4d2e9b6 to 0fe1d6d Compare May 6, 2024 13:01
@ondrejmirtes ondrejmirtes merged commit 1004481 into phpstan:1.11.x May 6, 2024
173 checks passed
@ondrejmirtes
Copy link
Member

Awesome job! Thank you.

@schlndh schlndh deleted the feature-checkRedeclaredReadonlyPropertiesV2 branch May 6, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants