1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Merge pull request #8955 from Nicelocal/fix

Fix bug
This commit is contained in:
orklah 2022-12-20 18:47:52 +01:00 committed by GitHub
commit a89bbc3353
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 68 additions and 5 deletions

View File

@ -771,14 +771,14 @@ class Methods
if (((!$old_contained_by_new && !$new_contained_by_old)
|| ($old_contained_by_new && $new_contained_by_old))
&& !$candidate_type->hasTemplate()
&& !$overridden_storage->return_type->hasTemplate()
&& !$overridden_storage_return_type->hasTemplate()
) {
$attempted_intersection = null;
if ($old_contained_by_new) { //implicitly $new_contained_by_old as well
try {
$attempted_intersection = Type::intersectUnionTypes(
$candidate_type,
$overridden_storage->return_type,
$overridden_storage_return_type,
$source_analyzer->getCodebase(),
);
} catch (InvalidArgumentException $e) {
@ -786,7 +786,7 @@ class Methods
}
} else {
$attempted_intersection = Type::intersectUnionTypes(
$overridden_storage->return_type,
$overridden_storage_return_type,
$candidate_type,
$source_analyzer->getCodebase(),
);
@ -803,7 +803,7 @@ class Methods
return $candidate_type;
}
if ($old_contained_by_new) {
if ($old_contained_by_new || $overridden_storage_return_type->hasTemplate()) {
$self_class = $appearing_fq_class_storage->name;
return $candidate_type;
@ -811,7 +811,7 @@ class Methods
$self_class = $overridden_method_id->fq_class_name;
return $overridden_storage->return_type;
return $overridden_storage_return_type;
}
}

View File

@ -16,6 +16,69 @@ class ClassTemplateExtendsTest extends TestCase
public function providerValidCodeParse(): iterable
{
return [
'interface' => [
'code' => '<?php
/**
* Singleton interface
*
* @template T
*/
interface ISingleton {
/**
* getInstance interface
*
* @return T
*/
public static function getInstance();
}
/**
* @psalm-consistent-constructor
*
* @implements ISingleton<Singleton&static>
*/
abstract class Singleton implements ISingleton {
/**
* By default, disallow construction of child classes.
*/
protected function __construct() {
}
/**
* Instance array
*
* @var array<class-string<static>, static>
*/
private static array $instances = [];
/**
* Clear all instances
*/
public static function clear(): void {
self::$instances = [];
}
/**
* Get instance
*/
public static function getInstance(): static {
$class = static::class;
return self::$instances[$class] ??= new static();
}
}
class a extends Singleton {
}
$a = a::getInstance();
',
'assertions' => [
'$a===' => 'a',
],
],
'phanTuple' => [
'code' => '<?php
namespace Phan\Library;