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

Fix stub parent class not loaded. #7110

Merged
merged 7 commits into from Jan 22, 2022

Conversation

AndrolGenhald
Copy link
Collaborator

@AndrolGenhald AndrolGenhald commented Dec 9, 2021

Fix stub file classes not being correctly referenced as parent classes in non-stub files, preventing checks ensuring property and function types match.

@AndrolGenhald
Copy link
Collaborator Author

It looks like stub files are always loaded last, and changing that causes a bunch of tests to break. Not sure how much work it would take to fix that, although that seems like it would be the preferable solution. I'm guessing it was done this way to make sure actual classes were preferred over stubs?
If that doesn't work, there are some places that use placeholder values that are resolved later, so that might work here. I forget what they're called though, so I'm not sure what to search for to look through how that's implemented.

@weirdan
Copy link
Collaborator

weirdan commented Dec 9, 2021

What are you trying to fix anyway?

I'm guessing it was done this way to make sure actual classes were preferred over stubs?

It's the opposite, actually. Stubs are loaded last to make sure they override everything they need to override.

@AndrolGenhald
Copy link
Collaborator Author

What are you trying to fix anyway?

SystemClass::foo takes (int, string), Foo::foo takes (string, string). There should be a ImplementedParamTypeMismatch issue.

I noticed this in #7107 after disabling the soap extension, MethodSignatureTest::testExtendDocblockParamTypeWithWrongDocblockParam started failing.

@weirdan
Copy link
Collaborator

weirdan commented Dec 9, 2021

SystemClass::foo takes (int, string), Foo::foo takes (string, string). There should be a ImplementedParamTypeMismatch issue.

The issue is not supposed to be emitted for stubs. Otherwise you would not be able to override wrong signatures coming from libraries/reflection - and it's one of the main problems solved by stubs.

@AndrolGenhald
Copy link
Collaborator Author

The issue is not supposed to be emitted for stubs.

It shouldn't be emitted when checking the stub itself, but shouldn't it be emitted when checking a non-stubbed class that extends a stubbed class?

@weirdan
Copy link
Collaborator

weirdan commented Dec 9, 2021

Ok, gotcha. Yes, it should be emitted in this case.

Comment on lines -377 to +437
private function populateDataFromTraits(
private function populateDataFromTrait(
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 pulled the loops out of these functions because in a previous version I was running them individually on specific dependencies. I later realized that line 295 already reruns the entire thing anyway, but I left the changes here because there were other improvements done as well.

Comment on lines 318 to 289
private function populateOverriddenMethods(
ClassLikeStorage $storage
ClassLikeStorage $storage,
ClassLikeStorageProvider $storage_provider
): void {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was pulled out of populateDataFromImplementedInterfaces when I removed the loop from it, so that it could be done afterward. I think it's actually easier to understand this way, one issue that took me a while to figure out is that $storage->class_implements may already have had items set elsewhere (from Reflection I believe), so this is actually populating overridden methods that were set elsewhere as well as from this class.

@@ -601,255 +691,152 @@ function ($constant) {
$storage->pseudo_methods += $parent_storage->pseudo_methods;
}

private function populateInterfaceDataFromParentInterfaces(
private function populateInterfaceData(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is common code pulled out of populateInterfaceDataFromParentInterfaces and populateDataFromImplementedInterfaces.

@orklah
Copy link
Collaborator

orklah commented Dec 14, 2021

Seems ok to me. If @weirdan approves, we can merge

@weirdan weirdan self-requested a review December 15, 2021 10:18
@AndrolGenhald
Copy link
Collaborator Author

@weirdan Any update on this?

@@ -373,7 +373,7 @@ class ClassLikeStorage
public $initialized_properties = [];

/**
* @var array<string>
* @var array<string, true>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is BC break. Good thing that the PR already targets master.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, good point, I'd completely forgotten about plugins. I'll take more care about that in the future.

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 don't think that change is really needed anymore, but unless you object I don't really see a need to change it back. It seems better to me for it to be a set rather than a list, and array<string, true> seems like the closest thing PHP has to a native string set without using the ds extension.
Or maybe it'd be better to change it back and methodically update a lot of these types of properties to be more set-like in a separate pull request instead?

Looks like I actually did end up using it to fix indirect circular references. Still, is changing more of these to be set-like something we should consider?

@weirdan weirdan added this to the Psalm 5 milestone Jan 4, 2022
@weirdan
Copy link
Collaborator

weirdan commented Jan 4, 2022

Sorry, I have been busy with v5 changes. I'll review it this week.

@orklah
Copy link
Collaborator

orklah commented Jan 22, 2022

@AndrolGenhald can you rebase this? We'll merge it like that I think.

@AndrolGenhald
Copy link
Collaborator Author

AndrolGenhald commented Jan 22, 2022

@orklah Done. There are some CS errors locally due to empty files, looks like TAssertionEmpty and TAssertionFalsy got accidentally undeleted in your description refactor.

Edit: Just a moment, I'll add a BC break note as well.

@orklah
Copy link
Collaborator

orklah commented Jan 22, 2022

TAssertionEmpty and TAssertionFalsy got accidentally undeleted

fixed, sorry

@orklah orklah added the release:fix The PR will be included in 'Fixes' section of the release notes label Jan 22, 2022
@orklah
Copy link
Collaborator

orklah commented Jan 22, 2022

Thanks!

@orklah orklah merged commit c3ad520 into vimeo:master Jan 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Need review release:fix The PR will be included in 'Fixes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants