mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Fix replacement for inherited methods
This commit is contained in:
parent
4002504ff0
commit
534e4c034b
@ -2220,15 +2220,19 @@ class CallAnalyzer
|
||||
&& strpos($cased_method_id, '::')
|
||||
&& !strpos($cased_method_id, '__')
|
||||
) {
|
||||
$method_storage = $codebase->methods->getStorage($cased_method_id);
|
||||
$declaring_method_id = $codebase->methods->getDeclaringMethodId($cased_method_id);
|
||||
|
||||
if (!isset($method_storage->possible_param_types[$argument_offset])) {
|
||||
$method_storage->possible_param_types[$argument_offset] = clone $input_type;
|
||||
} else {
|
||||
$method_storage->possible_param_types[$argument_offset] = Type::combineUnionTypes(
|
||||
$method_storage->possible_param_types[$argument_offset],
|
||||
clone $input_type
|
||||
);
|
||||
if ($declaring_method_id) {
|
||||
$method_storage = $codebase->methods->getStorage($declaring_method_id);
|
||||
|
||||
if (!isset($method_storage->possible_param_types[$argument_offset])) {
|
||||
$method_storage->possible_param_types[$argument_offset] = clone $input_type;
|
||||
} else {
|
||||
$method_storage->possible_param_types[$argument_offset] = Type::combineUnionTypes(
|
||||
$method_storage->possible_param_types[$argument_offset],
|
||||
clone $input_type
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,30 @@ class ParamTypeManipulationTest extends FileManipulationTest
|
||||
['MissingParamType'],
|
||||
true,
|
||||
],
|
||||
'noStringParamTypeParent' => [
|
||||
'<?php
|
||||
class C {
|
||||
public function fooFoo($a): void {}
|
||||
}
|
||||
|
||||
class D extends C {}
|
||||
|
||||
(new D)->fooFoo("hello");',
|
||||
'<?php
|
||||
class C {
|
||||
/**
|
||||
* @param string $a
|
||||
*/
|
||||
public function fooFoo($a): void {}
|
||||
}
|
||||
|
||||
class D extends C {}
|
||||
|
||||
(new D)->fooFoo("hello");',
|
||||
'7.1',
|
||||
['MissingParamType'],
|
||||
true,
|
||||
],
|
||||
'stringParamTypeNoOp' => [
|
||||
'<?php
|
||||
class C {
|
||||
|
Loading…
x
Reference in New Issue
Block a user