mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Add support for T of Foo
This commit is contained in:
parent
9a827c48ae
commit
ee97c9dbaf
@ -378,7 +378,9 @@ class CommentAnalyzer
|
||||
foreach ($all_templates as $template_line) {
|
||||
$template_type = preg_split('/[\s]+/', $template_line);
|
||||
|
||||
if (count($template_type) > 2 && in_array(strtolower($template_type[1]), ['as', 'super'], true)) {
|
||||
if (count($template_type) > 2
|
||||
&& in_array(strtolower($template_type[1]), ['as', 'super', 'of'], true)
|
||||
) {
|
||||
$info->templates[] = [
|
||||
$template_type[0],
|
||||
strtolower($template_type[1]), $template_type[2]
|
||||
@ -516,7 +518,9 @@ class CommentAnalyzer
|
||||
foreach ($comments['specials']['template'] as $template_line) {
|
||||
$template_type = preg_split('/[\s]+/', $template_line);
|
||||
|
||||
if (count($template_type) > 2 && in_array(strtolower($template_type[1]), ['as', 'super'], true)) {
|
||||
if (count($template_type) > 2
|
||||
&& in_array(strtolower($template_type[1]), ['as', 'super', 'of'], true)
|
||||
) {
|
||||
$info->templates[] = [
|
||||
$template_type[0],
|
||||
strtolower($template_type[1]), $template_type[2]
|
||||
|
@ -979,6 +979,23 @@ class TemplateTest extends TestCase
|
||||
bar(new Foo());
|
||||
bar(new FooChild());',
|
||||
],
|
||||
'classTemplateOfCorrect' => [
|
||||
'<?php
|
||||
class Foo {}
|
||||
class FooChild extends Foo {}
|
||||
|
||||
/**
|
||||
* @template T of Foo
|
||||
* @param T $x
|
||||
* @return T
|
||||
*/
|
||||
function bar($x) {
|
||||
return $x;
|
||||
}
|
||||
|
||||
bar(new Foo());
|
||||
bar(new FooChild());',
|
||||
],
|
||||
'classTemplateAsInterface' => [
|
||||
'<?php
|
||||
interface Foo {}
|
||||
|
Loading…
Reference in New Issue
Block a user