mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Prevent empty array workaround to #2308
This commit is contained in:
parent
06b64a4a01
commit
64996f464e
@ -814,7 +814,10 @@ class TypeAnalyzer
|
||||
$allow_float_int_equality,
|
||||
$atomic_comparison_result
|
||||
)) {
|
||||
if ($allow_interface_equality || $input_type_part instanceof TArray) {
|
||||
if ($allow_interface_equality
|
||||
|| ($input_type_part instanceof TArray
|
||||
&& !$input_type_part->type_params[1]->isEmpty())
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -677,9 +677,21 @@ class ClassTemplateExtendsTest extends TestCase
|
||||
|
||||
class Collection3 extends Collection2{}
|
||||
|
||||
$a = new Collection1(["a" => "b"]);
|
||||
$a = new Collection2(["a" => "b"]);
|
||||
$a = new Collection3(["a" => "b"]);',
|
||||
foreach ((new Collection1(["a" => "b"])) as $a) {}
|
||||
|
||||
/** @psalm-suppress MixedAssignment */
|
||||
foreach ((new Collection2(["a" => "b"])) as $a) {}
|
||||
|
||||
/** @psalm-suppress MixedAssignment */
|
||||
foreach ((new Collection3(["a" => "b"])) as $a) {}
|
||||
|
||||
foreach ((new Collection1([])) as $i) {}
|
||||
|
||||
/** @psalm-suppress MixedAssignment */
|
||||
foreach ((new Collection2([])) as $i) {}
|
||||
|
||||
/** @psalm-suppress MixedAssignment */
|
||||
foreach ((new Collection3([])) as $i) {}',
|
||||
],
|
||||
'iterateOverExtendedArrayObjectWithoutParam' => [
|
||||
'<?php
|
||||
|
@ -2397,7 +2397,7 @@ class ClassTemplateTest extends TestCase
|
||||
function expectsShape($_): void {}',
|
||||
'error_message' => 'MixedArgumentTypeCoercion'
|
||||
],
|
||||
'preventUseWithMoreSpecificParam' => [
|
||||
'preventUseWithMoreSpecificParamInt' => [
|
||||
'<?php
|
||||
/** @template T */
|
||||
abstract class Collection {
|
||||
@ -2414,6 +2414,23 @@ class ClassTemplateTest extends TestCase
|
||||
}',
|
||||
'error_message' => 'InvalidArgument'
|
||||
],
|
||||
'preventUseWithMoreSpecificParamEmptyArray' => [
|
||||
'<?php
|
||||
/** @template T */
|
||||
abstract class Collection {
|
||||
/** @param T $elem */
|
||||
public function add($elem): void {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param Collection<T> $col
|
||||
*/
|
||||
function usesCollection(Collection $col): void {
|
||||
$col->add([]);
|
||||
}',
|
||||
'error_message' => 'InvalidArgument'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user