1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Fix null ref

This commit is contained in:
Matthew Brown 2019-01-19 16:01:43 -05:00
parent 44b51cdf8e
commit e28bf1a29b
2 changed files with 53 additions and 3 deletions

View File

@ -577,9 +577,9 @@ class CommentAnalyzer
|| isset($comments['specials']['extends']) || isset($comments['specials']['extends'])
) { ) {
$all_inheritance = array_merge( $all_inheritance = array_merge(
$comments['specials']['template-extends'] ?: [], $comments['specials']['template-extends'] ?? [],
$comments['specials']['inherits'] ?: [], $comments['specials']['inherits'] ?? [],
$comments['specials']['extends'] ?: [] $comments['specials']['extends'] ?? []
); );
foreach ($all_inheritance as $template_line) { foreach ($all_inheritance as $template_line) {

View File

@ -1627,6 +1627,56 @@ class TemplateTest extends TestCase
'$f2' => 'Foo', '$f2' => 'Foo',
] ]
], ],
'supportBareExtends' => [
'<?php
/**
* @template T
*/
abstract class Container
{
/**
* @return T
*/
public abstract function getItem();
}
class Foo
{
}
/**
* @extends Container<Foo>
*/
class FooContainer extends Container
{
/**
* @return Foo
*/
public function getItem()
{
return new Foo();
}
}
/**
* @template TItem
* @param Container<TItem> $c
* @return TItem
*/
function getItemFromContainer(Container $c) {
return $c->getItem();
}
$fc = new FooContainer();
$f1 = $fc->getItem();
$f2 = getItemFromContainer($fc);',
[
'$fc' => 'FooContainer',
'$f1' => 'Foo',
'$f2' => 'Foo',
]
],
'allowExtendingParameterisedTypeParam' => [ 'allowExtendingParameterisedTypeParam' => [
'<?php '<?php
/** /**