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

Alter removes a reference variable, breaking the code after #6114

Closed
williamdes opened this issue Jul 15, 2021 · 3 comments
Closed

Alter removes a reference variable, breaking the code after #6114

williamdes opened this issue Jul 15, 2021 · 3 comments

Comments

@williamdes
Copy link

williamdes commented Jul 15, 2021

https://psalm.dev/r/7e011cd6cc

Source: https://github.com/phpmyadmin/phpmyadmin/blob/1835ebb4fccc20aa06868be88ab8bcaa9c395ccf/libraries/classes/Display/Results.php#L333

It removes the assignment ($relDb = &), but if you do that the code below will not work.

Same here:

diff --git a/libraries/classes/Plugins/Schema/Pdf/Pdf.php b/libraries/classes/Plugins/Schema/Pdf/Pdf.php
index 6e3dae46b2..90f956648e 100644
--- a/libraries/classes/Plugins/Schema/Pdf/Pdf.php
+++ b/libraries/classes/Plugins/Schema/Pdf/Pdf.php
@@ -398,7 +398,7 @@ class Pdf extends PdfLib
      */
     public function numLines($w, $txt)
     {
-        $cw = &$this->CurrentFont['cw'];
+        $this->CurrentFont['cw'];
         if ($w == 0) {
             $w = $this->w - $this->rMargin - $this->x;
         }
@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/7e011cd6cc
<?php
class A {
    /** @var array */
    private $transformationInfo = [];
    
    function foo(): void {
        global $cfgRelation;
       
        $this->transformationInfo[$cfgRelation['db']] = [];
        $relDb = &$this->transformationInfo[$cfgRelation['db']];
            if (! empty($cfgRelation['history'])) {
                $relDb[$cfgRelation['history']] = ['sqlquery' => $sqlHighlightingData];
            }

            if (! empty($cfgRelation['bookmark'])) {
                $relDb[$cfgRelation['bookmark']] = ['query' => $sqlHighlightingData];
            }

    }
}
Psalm output (using commit c5190f0):

INFO: MixedArrayAccess - 9:35 - Cannot access array value on mixed variable $cfgRelation

INFO: MixedArrayOffset - 9:9 - Cannot access value on variable $this->transformationInfo[mixed] using mixed offset

INFO: MixedArrayAccess - 10:45 - Cannot access array value on mixed variable $cfgRelation

INFO: MixedArrayOffset - 10:19 - Cannot access value on variable $this->transformationInfo using mixed offset

INFO: MixedAssignment - 10:9 - Unable to determine the type that $relDb is being assigned to

ERROR: UndefinedVariable - 12:66 - Cannot find referenced variable $sqlHighlightingData

INFO: MixedArrayAccess - 12:24 - Cannot access array value on mixed variable $cfgRelation

INFO: MixedArrayAssignment - 12:17 - Cannot access array value on mixed variable $relDb[mixed]

INFO: MixedArrayOffset - 12:17 - Cannot access value on variable $relDb[mixed] using mixed offset

ERROR: UndefinedVariable - 16:64 - Cannot find referenced variable $sqlHighlightingData

INFO: MixedArrayAccess - 16:24 - Cannot access array value on mixed variable $cfgRelation

INFO: MixedArrayAssignment - 16:17 - Cannot access array value on mixed variable $relDb[mixed]

INFO: MixedArrayOffset - 16:17 - Cannot access value on variable $relDb[mixed] using mixed offset

INFO: UnusedVariable - 10:9 - $relDb is never referenced or the value is not used

@orklah
Copy link
Collaborator

orklah commented Jul 17, 2021

Psalm already prevent emitting UnusedVariable on references. After #6129, it will also do that for globals. I think it'd also need to do it for variables that are references of others.

@AndrolGenhald
Copy link
Collaborator

I believe this is now fixed, likely by #7339. I tested by:

  • Checking out that phpmyadmin commit
  • composer update
  • vendor/bin/psalm --alter --issues=UnusedVariable libraries/classes/Display/Results.php

And $relDb = & was removed, then:

  • git checkout .
  • composer require --dev vimeo/psalm="dev-master"
  • Fix psalm.xml by removing totallyTyped="false"
  • vendor/bin/psalm --alter --issues=UnusedVariable libraries/classes/Display/Results.php

And the line is not changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants