mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
parent
f40b6625eb
commit
b48021dbfd
@ -568,6 +568,7 @@ class ReturnTypeAnalyzer
|
||||
if (!$ignore_nullable_issues
|
||||
&& $inferred_return_type->isNullable()
|
||||
&& !$declared_return_type->isNullable()
|
||||
&& !$declared_return_type->hasTemplate()
|
||||
&& !$declared_return_type->isVoid()
|
||||
) {
|
||||
if ($codebase->alter_code
|
||||
|
@ -375,12 +375,13 @@ class ReturnAnalyzer
|
||||
if (!$stmt_type->ignore_nullable_issues
|
||||
&& $inferred_type->isNullable()
|
||||
&& !$local_return_type->isNullable()
|
||||
&& !$local_return_type->hasTemplate()
|
||||
) {
|
||||
if (IssueBuffer::accepts(
|
||||
new NullableReturnStatement(
|
||||
'The declared return type \'' . $local_return_type . '\' for '
|
||||
'The declared return type \'' . $local_return_type->getId() . '\' for '
|
||||
. $cased_method_id . ' is not nullable, but the function returns \''
|
||||
. $inferred_type . '\'',
|
||||
. $inferred_type->getId() . '\'',
|
||||
new CodeLocation($source, $stmt->expr)
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
|
@ -2168,6 +2168,40 @@ class ClassTemplateTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'nullableTemplateAs' => [
|
||||
'<?php
|
||||
/**
|
||||
* @template T of null|array
|
||||
*/
|
||||
class Foo
|
||||
{
|
||||
private ?\ArrayObject $arrayObject;
|
||||
|
||||
public function __construct(?\ArrayObject $arrayObject)
|
||||
{
|
||||
$this->arrayObject = $arrayObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-assert-if-true Foo<array> $this
|
||||
* @psalm-assert-if-true ArrayObject $this->arrayObject
|
||||
*/
|
||||
public function hasArray(): bool
|
||||
{
|
||||
return $this->arrayObject instanceof \ArrayObject;
|
||||
}
|
||||
|
||||
/** @return T */
|
||||
public function toMaybeArray()
|
||||
{
|
||||
if ($this->hasArray()) {
|
||||
return $this->arrayObject->getArrayCopy();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user