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

MethodSignatureMismatch in presence of array parameter (when using preloadClasses) #5626

Closed
markrandall opened this issue Apr 14, 2021 · 1 comment · Fixed by #6213
Closed
Labels

Comments

@markrandall
Copy link

markrandall commented Apr 14, 2021

I have an odd situation that I am unable to reproduce using psalm.dev regarding what I believe is a false positive when inheriting a method with list (or array).

The code looks something like this: https://psalm.dev/r/b8d39294ea

Locally, I get the following (although each one is deep in a namespace):

ERROR: MethodSignatureMismatch - DefaultEncoderReconciler.php:31:33 - Argument 1 of DefaultEncoderReconciler::reconcile has wrong type 'array<array-key, mixed>', expecting 'list' as defined by EncoderReconcilerInterface::reconcile

If I widen the param type in the DefaultEncoderReconciler by removing the actual array, the error does not occur.

This may be related to #5126 as it also refers to the array typehint overriding the phpdoc which appears to be what is happening in this case.

Error:

  class DefaultEncoderReconciler implements EncoderReconcilerInterface, PublicService { 
       /**
       * @param list<Encoder> $encoders
       */
 	  public function reconcile(array $encoders, bool $foo = false): void { }
  }

No Error:

  class DefaultEncoderReconciler implements EncoderReconcilerInterface, PublicService { 
       /**
       * @param list<Encoder> $encoders
       */
 	  public function reconcile($encoders, bool $foo = false): void { }
  }

After failing to create a reproduction on psalm.dev I started stripping away code and configuration line by line until I discovered what appears to be the trigger; the presence of preloadClasses="true" in a stub.

  <stubs>
          <file name="any-stub-file.php" preloadClasses="true" />
      </stubs>

Triggers the error. Removing preloadClasses="true" also removes the error.

Version: dev-master@93e9054f98b040bf246c2023201503db3dbf162c

@psalm-github-bot
Copy link

I found these snippets:

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

class ParentType { 
       
}

class Encoder extends ParentType { 
    
}

interface PublicService { 
    
}

interface EncoderReconcilerInterface { 
    /**
     * @param list<Encoder> $encoders
     */
 	public function reconcile(array $encoders, bool $foo = false): void { 
        
    }
}

class DefaultEncoderReconciler implements EncoderReconcilerInterface, PublicService { 
     /**
     * @param list<Encoder> $encoders
     */
 	public function reconcile(array $encoders, bool $foo = false): void { 
        
    }
}
Psalm output (using commit 93e9054):

No issues!

@weirdan weirdan added the bug label Apr 14, 2021
weirdan added a commit to weirdan/psalm that referenced this issue Jul 31, 2021
This should prevent Psalm from sometimes marking user-defined classes as
built-in.

Fixes vimeo#5126
Fixes vimeo#5626
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants