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

Unused global variable after modification #6129

Merged
merged 3 commits into from
Jul 17, 2021
Merged

Conversation

orklah
Copy link
Collaborator

@orklah orklah commented Jul 17, 2021

This would fix #6111 (comment)

This basically registers every global variable and prevent emitting UnusedVariable on those.

This means true positives (where UnusedVariable was emitted and the variable was not used) won't work anymore: https://psalm.dev/r/edb1c159ea. Hence the failing test here

However, this bring the behaviour closer to what already exists for references: https://psalm.dev/r/67292ae85a

Going beyond that would mean Psalm would have to record not only variable read access detecting usage but also write access. This seems a big piece of work for detecting a few globals and references unused.

If this is good enough to be merged, I'll remove the failing test and this will become the new behaviour for those cases.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/edb1c159ea
<?php

function scope(){
    global $a;
}
Psalm output (using commit 2127da3):

INFO: UnusedVariable - 4:12 - $a is never referenced or the value is not used

INFO: MissingReturnType - 3:10 - Method scope does not have a return type, expecting void
https://psalm.dev/r/67292ae85a
<?php

    function setProxySettingsFromEnv(string $ref): void
    {
		$ref2 = &$ref;   
    }

	function setProxySettingsFromEnv2(string &$ref): void
    {
		
    }
Psalm output (using commit 2127da3):

No issues!

@weirdan
Copy link
Collaborator

weirdan commented Jul 17, 2021

If this is good enough to be merged,

I think it is.

@orklah
Copy link
Collaborator Author

orklah commented Jul 17, 2021

Thanks :)

Test is removed

@weirdan weirdan merged commit 53ae776 into vimeo:master Jul 17, 2021
@weirdan
Copy link
Collaborator

weirdan commented Jul 17, 2021

Thanks!

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.

obvious WTF UnusedVariable case
2 participants