mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #2306 - allow nullable templated params to be compared to null
This commit is contained in:
parent
818f0c0985
commit
b81a2d3852
@ -721,11 +721,21 @@ class TypeAnalyzer
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($input_type_part instanceof TNull && $container_type_part instanceof TNull) {
|
||||
return true;
|
||||
if ($input_type_part instanceof TNull) {
|
||||
if ($container_type_part instanceof TNull) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($container_type_part instanceof TTemplateParam
|
||||
&& $container_type_part->as->isNullable()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($input_type_part instanceof TNull || $container_type_part instanceof TNull) {
|
||||
if ($container_type_part instanceof TNull) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1943,6 +1943,29 @@ class ClassTemplateTest extends TestCase
|
||||
return ["foo", "baz"];
|
||||
}'
|
||||
],
|
||||
'allowInternalNullCheck' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template TP as ?scalar
|
||||
*/
|
||||
class Entity
|
||||
{
|
||||
/**
|
||||
* @var TP
|
||||
*/
|
||||
private $parent;
|
||||
|
||||
/** @param TP $parent */
|
||||
public function __construct($parent) {
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
public function hasNoParent() : bool
|
||||
{
|
||||
return $this->parent === null; // So TP does contain null
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user