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

Prevent crash when method being called does not exist in reflection

Crash seen when running this test in PHP 7.4 because the method does not exist, but the call map includes it in 8.0
This commit is contained in:
Matthew Brown 2021-05-13 12:40:39 -04:00
parent 4873f53f69
commit cc7ff94f7c
4 changed files with 27 additions and 0 deletions

View File

@ -87,6 +87,10 @@ class MethodAnalyzer extends FunctionLikeAnalyzer
$method_id = $codebase_methods->getDeclaringMethodId($method_id);
if (!$method_id) {
if (\Psalm\Internal\Codebase\InternalCallMapHandler::inCallMap((string) $original_method_id)) {
return true;
}
throw new \LogicException('Declaring method for ' . $original_method_id . ' should not be null');
}

View File

@ -69,6 +69,10 @@ class MethodVisibilityAnalyzer
return null;
}
if (\Psalm\Internal\Codebase\InternalCallMapHandler::inCallMap((string) $method_id)) {
return null;
}
throw new \UnexpectedValueException('$declaring_method_id not expected to be null here');
}

View File

@ -1101,6 +1101,10 @@ class Methods
$declaring_method_id = $this->getDeclaringMethodId($method_id);
if (!$declaring_method_id) {
if (\Psalm\Internal\Codebase\InternalCallMapHandler::inCallMap((string) $method_id)) {
return null;
}
throw new \UnexpectedValueException('$storage should not be null for ' . $method_id);
}

View File

@ -969,6 +969,21 @@ class MethodCallTest extends TestCase
}
}'
],
'noCrashWhenCallingParent' => [
'<?php
namespace FooBar;
class Datetime extends \DateTime
{
public static function createFromInterface(\DatetimeInterface $datetime): \DateTime
{
return parent::createFromInterface($datetime);
}
}',
[],
['MixedReturnStatement', 'MixedInferredReturnType'],
'8.0'
]
];
}