Skip to content
Permalink
Browse files

Fix #2473 - allow array_map to work with callables returning static

  • Loading branch information
muglug committed Dec 16, 2019
1 parent 7cb021a commit 529efaa29c147503775b7c2b9baf0045cb3292fc
@@ -127,6 +127,8 @@ public static function getFunctionReturnType(
continue;
}

$class_storage = $codebase->classlike_storage_provider->get($callable_fq_class_name);

if (!$codebase->methods->methodExists(
$mapping_function_id_part,
$context->calling_method_id,
@@ -150,12 +152,18 @@ public static function getFunctionReturnType(
$self_class
) ?: Type::getMixed();

$static_class = $self_class;

if ($self_class !== 'self') {
$static_class = $class_storage->name;
}

$return_type = ExpressionAnalyzer::fleshOutType(
$codebase,
$return_type,
$self_class,
$self_class,
$statements_source->getParentFQCLN()
$static_class,
$class_storage->parent_class
);

if ($mapping_return_type) {
@@ -654,6 +654,57 @@ public static function bar(): string { return "asd"; }
new Func("f", ["\Foo", "bar"]);',
],
'staticReturningCallable' => [
'<?php
abstract class Id
{
/**
* @var string
*/
private $id;
final protected function __construct(string $id)
{
$this->id = $id;
}
/**
* @return static
*/
final public static function fromString(string $id): self
{
return new static($id);
}
}
final class CriterionId extends Id
{
}
final class CriterionIds
{
/**
* @psalm-var non-empty-list<CriterionId>
*/
private $ids;
/**
* @psalm-param non-empty-list<CriterionId> $ids
*/
private function __construct(array $ids)
{
$this->ids = $ids;
}
/**
* @psalm-param non-empty-list<string> $ids
*/
public static function fromStrings(array $ids): self
{
return new self(array_map([CriterionId::class, "fromString"], $ids));
}
}'
],
];
}

0 comments on commit 529efaa

Please sign in to comment.
You can’t perform that action at this time.