mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #6665
This commit is contained in:
parent
24f1b60e53
commit
244a90ca4f
@ -14,6 +14,7 @@ use function array_map;
|
||||
use function array_values;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function strpos;
|
||||
use function substr;
|
||||
|
||||
trait GenericTrait
|
||||
@ -102,6 +103,10 @@ trait GenericTrait
|
||||
return $value_type_string . '[]';
|
||||
}
|
||||
|
||||
$intersection_pos = strpos($base_value, '&');
|
||||
if ($intersection_pos !== false) {
|
||||
$base_value = substr($base_value, 0, $intersection_pos);
|
||||
}
|
||||
$type_params = $this->type_params;
|
||||
|
||||
//no need for special format if the key is not determined
|
||||
|
@ -6,6 +6,7 @@ use Psalm\Type\Atomic;
|
||||
use function array_merge;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function strrpos;
|
||||
use function substr;
|
||||
|
||||
/**
|
||||
@ -69,7 +70,16 @@ class TGenericObject extends TNamedObject
|
||||
int $php_major_version,
|
||||
int $php_minor_version
|
||||
): ?string {
|
||||
return $this->toNamespacedString($namespace, $aliased_classes, $this_class, true);
|
||||
$result = $this->toNamespacedString($namespace, $aliased_classes, $this_class, true);
|
||||
$intersection = strrpos($result, '&');
|
||||
if ($intersection === false || (
|
||||
($php_major_version === 8 && $php_minor_version >= 1) ||
|
||||
($php_major_version >= 9)
|
||||
)
|
||||
) {
|
||||
return $result;
|
||||
}
|
||||
return substr($result, $intersection+1);
|
||||
}
|
||||
|
||||
public function equals(Atomic $other_type, bool $ensure_source_equality): bool
|
||||
|
@ -872,6 +872,94 @@ class ReturnTypeManipulationTest extends FileManipulationTestCase
|
||||
false,
|
||||
true,
|
||||
],
|
||||
'Intersection80' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
class container1 {}
|
||||
/**
|
||||
* @template TT
|
||||
* @extends container1<TT>
|
||||
*/
|
||||
class container2 extends container1 {}
|
||||
|
||||
function ret() {
|
||||
/** @var container1<int>&container2<int> $a */
|
||||
$a = new container1;
|
||||
return $a;
|
||||
}
|
||||
',
|
||||
'<?php
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
class container1 {}
|
||||
/**
|
||||
* @template TT
|
||||
* @extends container1<TT>
|
||||
*/
|
||||
class container2 extends container1 {}
|
||||
|
||||
/**
|
||||
* @return container1&container2
|
||||
*
|
||||
* @psalm-return container1<int>&container2<int>
|
||||
*/
|
||||
function ret(): container2 {
|
||||
/** @var container1<int>&container2<int> $a */
|
||||
$a = new container1;
|
||||
return $a;
|
||||
}
|
||||
',
|
||||
'8.0',
|
||||
['MissingReturnType'],
|
||||
false,
|
||||
true,
|
||||
],
|
||||
'Intersection81' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
class container1 {}
|
||||
/**
|
||||
* @template TT
|
||||
* @extends container1<TT>
|
||||
*/
|
||||
class container2 extends container1 {}
|
||||
|
||||
function ret() {
|
||||
/** @var container1<int>&container2<int> $a */
|
||||
$a = new container1;
|
||||
return $a;
|
||||
}
|
||||
',
|
||||
'<?php
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
class container1 {}
|
||||
/**
|
||||
* @template TT
|
||||
* @extends container1<TT>
|
||||
*/
|
||||
class container2 extends container1 {}
|
||||
|
||||
/**
|
||||
* @psalm-return container1<int>&container2<int>
|
||||
*/
|
||||
function ret(): container1&container2 {
|
||||
/** @var container1<int>&container2<int> $a */
|
||||
$a = new container1;
|
||||
return $a;
|
||||
}
|
||||
',
|
||||
'8.1',
|
||||
['MissingReturnType'],
|
||||
false,
|
||||
true,
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user