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

Fix #2181 - prevent class template types being wiped by anonymous class use

This commit is contained in:
Matthew Brown 2019-09-27 12:58:32 -04:00
parent 81464d8dbf
commit 9af8a9ac38
2 changed files with 22 additions and 1 deletions

View File

@ -632,7 +632,9 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
$this->file_storage->has_docblock_issues = true;
}
$this->class_template_types = [];
if ($node->name) {
$this->class_template_types = [];
}
if ($this->after_classlike_check_plugins) {
$file_manipulations = [];

View File

@ -1703,6 +1703,25 @@ class ClassTemplateTest extends TestCase
}
}',
],
'anonymousClassMustNotBreakParentTemplate' => [
'<?php
/** @template T */
class Foo {
/** @psalm-var ?T */
private $value;
/** @psalm-param T $val */
public function set($val) : void {
$this->value = $val;
new class extends Foo {};
}
/** @psalm-return ?T */
public function get() {
return $this->value;
}
}'
],
];
}