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

Fix #2849 - allow object-like templated array comparison

This commit is contained in:
Brown 2020-02-21 15:13:07 -05:00
parent a2fbfc1c9e
commit f44a0f9f4c
2 changed files with 55 additions and 0 deletions

View File

@ -874,6 +874,7 @@ class TypeAnalyzer
if ($allow_interface_equality
|| ($input_type_part instanceof TArray
&& !$input_type_part->type_params[1]->isEmpty())
|| $input_type_part instanceof ObjectLike
) {
return true;
}

View File

@ -467,6 +467,60 @@ class ClassTemplateCovarianceTest extends TestCase
public function zip();
}',
],
'extendsArrayWithCovariant' => [
'<?php
/**
* @template-covariant T1
*/
interface IParentCollection {
/**
* @return IParentCollection<array<T1>>
*/
public function getNested(): IParentCollection;
}
/**
* @template T2
*
* @extends IParentCollection<T2>
*/
interface IChildCollection extends IParentCollection {
/**
* @return IChildCollection<array<T2>>
*/
public function getNested(): IChildCollection;
}',
[],
[],
'7.4',
],
'extendsObjectLikeWithCovariant' => [
'<?php
/**
* @template-covariant T1
*/
interface IParentCollection {
/**
* @return IParentCollection<array{0: T1}>
*/
public function getNested(): IParentCollection;
}
/**
* @template T2
*
* @extends IParentCollection<T2>
*/
interface IChildCollection extends IParentCollection {
/**
* @return IChildCollection<array{0: T2}>
*/
public function getNested(): IChildCollection;
}',
[],
[],
'7.4',
],
];
}