mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #2095 - respect @method annotations even when method already exists
This commit is contained in:
parent
de5df1e36a
commit
071fae98b2
@ -840,7 +840,10 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
$method_id,
|
||||
$context->calling_method_id,
|
||||
$method_id !== $source_method_id ? new CodeLocation($source, $stmt->name) : null
|
||||
)) {
|
||||
)
|
||||
|| ($config->use_phpdoc_method_without_magic_or_parent
|
||||
&& isset($class_storage->pseudo_methods[$method_name_lc]))
|
||||
) {
|
||||
$class_storage = $codebase->classlike_storage_provider->get($fq_class_name);
|
||||
|
||||
if (($is_interface || $config->use_phpdoc_method_without_magic_or_parent)
|
||||
|
@ -131,6 +131,28 @@ class MagicMethodAnnotationTest extends TestCase
|
||||
$this->assertSame('Child', (string) $context->vars_in_scope['$child']);
|
||||
}
|
||||
|
||||
public function testOverrideExceptionMethodReturn() : void
|
||||
{
|
||||
Config::getInstance()->use_phpdoc_method_without_magic_or_parent = true;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
/**
|
||||
* @method int getCode()
|
||||
*/
|
||||
class MyException extends Exception {}
|
||||
|
||||
function foo(MyException $e): int {
|
||||
return $e->getCode();
|
||||
}'
|
||||
);
|
||||
|
||||
$context = new Context();
|
||||
|
||||
$this->analyzeFile('somefile.php', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string,array{string,assertions?:array<string,string>,error_levels?:string[]}>
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user