Skip to content

Commit

Permalink
Fix #3380 - allow comparisons between template param and empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed May 16, 2020
1 parent f6342a4 commit 4dd0a2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Expand Up @@ -750,15 +750,11 @@ private static function scrapeEqualityAssertions(
&& ($var_type = $source->node_data->getType($base_conditional))
&& $conditional instanceof PhpParser\Node\Expr\BinaryOp\Identical
) {
$null_type = Type::getEmptyArray();
$empty_array_type = Type::getEmptyArray();

if (!TypeAnalyzer::isContainedBy(
$codebase,
$var_type,
$null_type
) && !TypeAnalyzer::isContainedBy(
if (!TypeAnalyzer::canExpressionTypesBeIdentical(
$codebase,
$null_type,
$empty_array_type,
$var_type
)) {
if ($var_type->from_docblock) {
Expand Down
13 changes: 13 additions & 0 deletions tests/Template/FunctionTemplateTest.php
Expand Up @@ -1254,6 +1254,19 @@ function foo(A $o):void {}
createProxy(A::class, \'Ns\foo\')->bar();',
],
'compareToEmptyArray' => [
'<?php
/**
* @template T
*
* @param T $a
* @return T
*/
function ex($a) {
if($a === []) {}
return $a;
}'
],
];
}

Expand Down

0 comments on commit 4dd0a2b

Please sign in to comment.