mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Fix #1282 - allow generic self and static
This commit is contained in:
parent
6033345694
commit
6d5c995458
@ -259,7 +259,10 @@ abstract class Type
|
||||
return new TClassString($class_name, $param_union_types[0]);
|
||||
}
|
||||
|
||||
if (isset(self::PSALM_RESERVED_WORDS[$generic_type_value])) {
|
||||
if (isset(self::PSALM_RESERVED_WORDS[$generic_type_value])
|
||||
&& $generic_type_value !== 'self'
|
||||
&& $generic_type_value !== 'static'
|
||||
) {
|
||||
throw new TypeParseTreeException('Cannot create generic object with reserved word');
|
||||
}
|
||||
|
||||
|
@ -1090,6 +1090,51 @@ class TemplateExtendsTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'genericStaticAndSelf' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
interface Functor
|
||||
{
|
||||
/**
|
||||
* @template U
|
||||
*
|
||||
* @param Closure(T):U $c
|
||||
*
|
||||
* @return static<U>
|
||||
*/
|
||||
public function map(Closure $c);
|
||||
}
|
||||
/**
|
||||
* @template T
|
||||
*/
|
||||
class Box implements Functor
|
||||
{
|
||||
/**
|
||||
* @var T
|
||||
*/
|
||||
public $value;
|
||||
/**
|
||||
* @param T $x
|
||||
*/
|
||||
public function __construct($x)
|
||||
{
|
||||
$this->value = $x;
|
||||
}
|
||||
/**
|
||||
* @template U
|
||||
*
|
||||
* @param Closure(T):U $c
|
||||
*
|
||||
* @return self<U>
|
||||
*/
|
||||
public function map(Closure $c)
|
||||
{
|
||||
return new Box($c($this->value));
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user