Skip to content

Commit

Permalink
Fix #6212 - remove untested code, add test for reasonable behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jul 31, 2021
1 parent edffb1a commit a205a23
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1045,20 +1045,16 @@ function ($lower_bound) {
continue;
}

$equality_classlikes = [];
$equality_types = [];

foreach ($bounds_with_equality as $bound_with_equality) {
$equality_classlikes[] = $bound_with_equality->equality_bound_classlike;
$equality_types[] = $bound_with_equality->type->getId();
}

$equality_classlikes = array_unique($equality_classlikes);
$equality_types = array_unique($equality_types);
$equality_types = array_unique(
array_map(
function($bound_with_equality) {
return $bound_with_equality->type->getId();
},
$bounds_with_equality
)
);

if (count($equality_classlikes) > 1
|| count($equality_types) > 1
) {
if (count($equality_types) > 1) {
if (IssueBuffer::accepts(
new InvalidArgument(
'Incompatible types found for ' . $template_name,
Expand Down
23 changes: 23 additions & 0 deletions tests/Template/ClassTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3554,6 +3554,29 @@ function foo(object $c, Collection $d): object {
return rand(0, 1) ? $c : $d->get();
}',
],
'allowCompatibleGenerics' => [
'<?php
/** @template T of object */
interface A {}
/** @template T of object */
interface B {}
/**
* @template T of object
* @param A<T> $a
* @param B<T> $b
*/
function foo(A $a, B $b): void {}
/**
* @param A<stdClass> $a
* @param B<stdClass> $b
*/
function bar(A $a, B $b): void {
foo($a, $b);
}'
],
];
}

Expand Down

0 comments on commit a205a23

Please sign in to comment.