mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix type transformation issues in templated class strings
This commit is contained in:
parent
43bbd739a2
commit
2201380c52
@ -934,8 +934,6 @@ class Union
|
||||
|
||||
foreach ($template_type->types as $template_type_part) {
|
||||
if ($template_type_part instanceof Type\Atomic\TMixed) {
|
||||
$is_mixed = true;
|
||||
|
||||
$unknown_class_string = new Type\Atomic\TClassString();
|
||||
|
||||
$new_types[$unknown_class_string->getKey()] = $unknown_class_string;
|
||||
|
@ -1239,6 +1239,41 @@ class TemplateTest extends TestCase
|
||||
}
|
||||
}',
|
||||
],
|
||||
'allowComparisonGetTypeResult' => [
|
||||
'<?php
|
||||
class Foo {}
|
||||
|
||||
/**
|
||||
* @template T as Foo
|
||||
*/
|
||||
class Collection {
|
||||
/**
|
||||
* @var class-string<T>
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @param class-string<T> $type
|
||||
*/
|
||||
public function __construct(string $type) {
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<T>|null
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
|
||||
function foo(Collection $c) : void {
|
||||
$val = $c->getType();
|
||||
if (!$val) {}
|
||||
if ($val) {}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -1151,6 +1151,14 @@ class TypeReconciliationTest extends TestCase
|
||||
if (!is_numeric($val)) {}
|
||||
}',
|
||||
],
|
||||
'classStringCanBeFalsy' => [
|
||||
'<?php
|
||||
/** @param class-string<stdClass>|null $val */
|
||||
function foo(?string $val) : void {
|
||||
if (!$val) {}
|
||||
if ($val) {}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user