mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Allow coercion from empty to array param
This commit is contained in:
parent
4ecf370900
commit
ec2ee04fe8
@ -1591,6 +1591,10 @@ class TypeAnalyzer
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($input_param->isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!self::isContainedBy(
|
||||
$codebase,
|
||||
$input_param,
|
||||
|
@ -2230,6 +2230,29 @@ class TemplateTest extends TestCase
|
||||
'$y' => 'array<array-key, A&B>',
|
||||
]
|
||||
],
|
||||
'templateEmptyParamCoercion' => [
|
||||
'<?php
|
||||
namespace NS;
|
||||
use Countable;
|
||||
|
||||
/** @template T */
|
||||
class Collection
|
||||
{
|
||||
/** @psalm-var iterable<T> */
|
||||
private $data;
|
||||
|
||||
/** @psalm-param iterable<T> $data */
|
||||
public function __construct(iterable $data = []) {
|
||||
$this->data = $data;
|
||||
}
|
||||
}
|
||||
|
||||
class Item {}
|
||||
/** @psalm-param Collection<Item> $c */
|
||||
function takesCollectionOfItems(Collection $c): void {}
|
||||
|
||||
takesCollectionOfItems(new Collection());',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -2757,35 +2780,6 @@ class TemplateTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'InvalidDocblock',
|
||||
],
|
||||
'noComparisonToEmpty' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template K
|
||||
* @template V
|
||||
*/
|
||||
class Container {
|
||||
/** @var array<K, V> */
|
||||
private $c;
|
||||
|
||||
/** @param array<K, V> $c */
|
||||
public function __construct(array $c) {
|
||||
$this->c = $c;
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
/**
|
||||
* @var Container<int, DateTime>
|
||||
*/
|
||||
private $c;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->c = new Container([]);
|
||||
}
|
||||
}',
|
||||
'error_message' => 'InvalidPropertyAssignmentValue'
|
||||
],
|
||||
'preventDogCatSnafu' => [
|
||||
'<?php
|
||||
class Animal {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user