1
0
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:
Brown 2019-05-31 10:37:26 -04:00
parent 4002504ff0
commit 534e4c034b
2 changed files with 36 additions and 8 deletions

View File

@ -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
);
}
}
}

View File

@ -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 {