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:
parent
11fbc15372
commit
b4f03abca6
@ -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);
|
||||
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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 []; });
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user