1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #1361 - flesh out array map return type before using

This commit is contained in:
Matthew Brown 2019-02-19 01:25:36 -05:00
parent dc23212fd4
commit cd2eb3edb9
2 changed files with 34 additions and 0 deletions

View File

@ -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,

View File

@ -702,6 +702,32 @@ class CallableTest extends TestCase
}
}',
],
'selfArrayMapCallableWrongClass' => [
'<?php
class Foo {
public function __construct(int $param) {}
public static function foo(int $param): Foo {
return new self($param);
}
public static function baz(int $param): self {
return new self($param);
}
}
class Bar {
/**
* @return array<int, Foo>
*/
public function bar() {
return array_map([Foo::class, "foo"], [1,2,3]);
}
/** @return array<int, Foo> */
public function bat() {
return array_map([Foo::class, "baz"], [1]);
}
}'
],
];
}