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:
parent
68cdbda8c7
commit
8d29b27204
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user