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:
parent
4873f53f69
commit
cc7ff94f7c
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user