1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #1886 - allow empty array to be coerced to a mixed one

This commit is contained in:
Matthew Brown 2019-07-05 17:44:22 -04:00
parent 11fbc15372
commit b4f03abca6
3 changed files with 28 additions and 0 deletions

View File

@ -1789,6 +1789,7 @@ class TypeAnalyzer
&& !$container_param->hasTemplate()
&& !$input_param->hasTemplate()
&& !$input_param->hasLiteralValue()
&& !$input_param->hasEmptyArray()
) {
$input_storage = $codebase->classlike_storage_provider->get($input_type_part->value);

View File

@ -569,6 +569,16 @@ class Union
return isset($this->types['array']);
}
/**
* @return bool
*/
public function hasEmptyArray()
{
return isset($this->types['array'])
&& $this->types['array'] instanceof Atomic\TArray
&& $this->types['array']->type_params[1]->isEmpty();
}
/**
* @return bool
*/

View File

@ -1601,6 +1601,23 @@ class ClassTemplateTest extends TestCase
return new TestPromise(true);
}',
],
'classTemplatedPropertyEmptyAssignment' => [
'<?php
/** @template T */
class Foo {
/** @param \Closure():T $closure */
public function __construct($closure) {}
}
class Bar {
/** @var Foo<array> */
private $FooArray;
public function __construct() {
$this->FooArray = new Foo(function(): array { return []; });
}
}',
],
];
}