Skip to content

Fix some minor issues with references.#7684

Merged
orklah merged 2 commits intovimeo:masterfrom
AndrolGenhald:bugfix/minor-reference-fixes
Feb 20, 2022
Merged

Fix some minor issues with references.#7684
orklah merged 2 commits intovimeo:masterfrom
AndrolGenhald:bugfix/minor-reference-fixes

Conversation

@AndrolGenhald
Copy link
Copy Markdown
Collaborator

References assigned to properties on $this should never be unused.
Using a @var docblock before a reference should be allowed if it targets a variable instead of the assignment statement.

References assigned to properties on `$this` should never be unused.
Using a `@var` docblock before a reference should be allowed if it targets a variable instead of the assignment statement.
@AndrolGenhald AndrolGenhald added the release:fix The PR will be included in 'Fixes' section of the release notes label Feb 17, 2022
@AndrolGenhald AndrolGenhald marked this pull request as draft February 17, 2022 16:28
@AndrolGenhald AndrolGenhald marked this pull request as ready for review February 17, 2022 16:40
}

if ($root_var_id === '$this') {
// Variables on `$this` are always used
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you mean that $this->whatever = $var constitutes a use of $var (but not necessarily $this->whatever)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, it constitutes use of $this->whatever as well. We don't currently seem to track unused properties, and this caused me some issues.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Reference assignment actually catches more than regular assignment for properties. I'm not too sure if it'd be better to just make it work the same or if non-reference assignment should be improved, so I decided to start small and make $this a special case.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We don't currently seem to track unused properties,

We actually do, but you have to use the class itself and enable Detect unused classes and methods checkbox on psalm.dev: https://psalm.dev/r/031e79174f

Copy link
Copy Markdown
Collaborator Author

@AndrolGenhald AndrolGenhald Feb 17, 2022

Choose a reason for hiding this comment

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

Ah, I missed that the class had to be used. That means this PR causes this to not mark Foo::$bar as unused, but I think that's an acceptable tradeoff for now. To fix it we'd need to somehow mark the assignment as used, but still keep the property itself as unused.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Seems ok if it only involves references

@orklah orklah merged commit b8cda9e into vimeo:master Feb 20, 2022
@orklah
Copy link
Copy Markdown
Collaborator

orklah commented Feb 20, 2022

Thanks!

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.

3 participants