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

Allow assigning null to template with null potential

This commit is contained in:
Brown 2020-04-18 15:34:14 -04:00
parent 68cdbda8c7
commit 8d29b27204
2 changed files with 40 additions and 2 deletions

View File

@ -791,7 +791,17 @@ class Union implements TypeNode
*/
public function isNullable()
{
return isset($this->types['null']);
if (isset($this->types['null'])) {
return true;
}
foreach ($this->types as $type) {
if ($type instanceof TTemplateParam && $type->as->isNullable()) {
return true;
}
}
return false;
}
/**
@ -799,7 +809,17 @@ class Union implements TypeNode
*/
public function isFalsable()
{
return isset($this->types['false']);
if (isset($this->types['false'])) {
return true;
}
foreach ($this->types as $type) {
if ($type instanceof TTemplateParam && $type->as->isFalsable()) {
return true;
}
}
return false;
}
/**

View File

@ -2655,6 +2655,24 @@ class ClassTemplateTest extends TestCase
[],
['MissingClosureParamType']
],
'templatedPropertyAllowsNull' => [
'<?php
/**
* @template TKey as string|null
*/
class A {
/** @var TKey */
public $key;
/**
* @param TKey $key
*/
public function __construct(?string $key)
{
$this->key = $key;
}
}'
],
];
}