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

iterable: Behavior difference based on array vs iterable #11183

Open
jarstelfox opened this issue Dec 11, 2024 · 1 comment
Open

iterable: Behavior difference based on array vs iterable #11183

jarstelfox opened this issue Dec 11, 2024 · 1 comment

Comments

@jarstelfox
Copy link
Contributor

https://psalm.dev/r/584b550264

Copy link

I found these snippets:

https://psalm.dev/r/584b550264
<?php


abstract class Base {
   /**
    * @return iterable<int, stdClass>
    */
   abstract function returnsIterable(): iterable;
}

class PsalmCatchesIssue extends Base { 
   function returnsIterable(): iterable {
       return [1, 2];
   }
}

class PsalmFailsToCatchIssue extends Base {
   function returnsIterable(): array { // only diff is array
       return [3, 4];
   }
}

class PsalmCatchesReturnTypeMismatch extends Base {
   /** @return array<int, int> */
   function returnsIterable(): array {
       return [5, 6];
   }
}
Psalm output (using commit a9b5291):

ERROR: InvalidReturnStatement - 13:15 - The inferred type 'list{1, 2}' does not match the declared return type 'iterable<int, stdClass>' for PsalmCatchesIssue::returnsIterable

ERROR: InvalidReturnType - 12:32 - The declared return type 'iterable<int, stdClass>' for PsalmCatchesIssue::returnsIterable is incorrect, got 'list{1, 2}'

ERROR: ImplementedReturnTypeMismatch - 24:16 - The inherited return type 'iterable<int, stdClass>' for Base::returnsIterable is different to the implemented return type for PsalmCatchesReturnTypeMismatch::returnsiterable 'array<int, int>'

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

No branches or pull requests

1 participant