diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php index 68bdc913f..ce88d9bec 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php @@ -7,6 +7,7 @@ use Psalm\CodeLocation; use Psalm\Context; use Psalm\StatementsSource; use Psalm\Internal\Analyzer\Statements\Expression\CallAnalyzer; +use Psalm\Internal\Analyzer\Statements\ExpressionAnalyzer; use Psalm\Internal\Codebase\CallMap; use Psalm\Type; @@ -174,6 +175,13 @@ class ArrayMapReturnTypeProvider implements \Psalm\Plugin\Hook\FunctionReturnTyp $self_class ) ?: Type::getMixed(); + $return_type = ExpressionAnalyzer::fleshOutType( + $codebase, + $return_type, + $self_class, + $self_class + ); + if ($mapping_return_type) { $mapping_return_type = Type::combineUnionTypes( $mapping_return_type, diff --git a/tests/CallableTest.php b/tests/CallableTest.php index f0e066925..1da473319 100644 --- a/tests/CallableTest.php +++ b/tests/CallableTest.php @@ -702,6 +702,32 @@ class CallableTest extends TestCase } }', ], + 'selfArrayMapCallableWrongClass' => [ + ' + */ + public function bar() { + return array_map([Foo::class, "foo"], [1,2,3]); + } + /** @return array */ + public function bat() { + return array_map([Foo::class, "baz"], [1]); + } + }' + ], ]; }