mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 13:51:54 +01:00
Merge pull request #8051 from AndrolGenhald/bugfix/8048
Fix possibly empty array shape appearing non-empty (fixes #8048).
This commit is contained in:
commit
02d5beecb0
@ -214,6 +214,10 @@ class ArrayMergeReturnTypeProvider implements FunctionReturnTypeProviderInterfac
|
||||
$inner_value_type = null;
|
||||
|
||||
if ($inner_key_types) {
|
||||
/**
|
||||
* Truthy&array-shape-list doesn't reconcile correctly, will be fixed for 5.x by #8050.
|
||||
* @psalm-suppress InvalidScalarArgument
|
||||
*/
|
||||
$inner_key_type = TypeCombiner::combine($inner_key_types, $codebase, true);
|
||||
}
|
||||
|
||||
|
@ -408,13 +408,15 @@ class TKeyedArray extends Atomic
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
public function getList(): TNonEmptyList
|
||||
public function getList(): TList
|
||||
{
|
||||
if (!$this->is_list) {
|
||||
throw new UnexpectedValueException('Object-like array must be a list for conversion');
|
||||
}
|
||||
|
||||
return new TNonEmptyList($this->getGenericValueType());
|
||||
return $this->isNonEmpty()
|
||||
? new TNonEmptyList($this->getGenericValueType())
|
||||
: new TList($this->getGenericValueType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1420,6 +1420,17 @@ class TypeAlgebraTest extends TestCase
|
||||
false,
|
||||
'8.1',
|
||||
],
|
||||
'arrayShapeListCanBeEmpty' => [
|
||||
'<?php
|
||||
/** @param non-empty-list<mixed> $_list */
|
||||
function foobar(array $_list): void {}
|
||||
|
||||
$list = random_int(0, 1) ? [] : ["foobar"];
|
||||
|
||||
foobar($list);
|
||||
',
|
||||
'error_message' => 'InvalidArgument',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user