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

Fix issue where byref differences would not be highlighted

This commit is contained in:
Matthew Brown 2018-01-04 14:01:17 -05:00
parent 9b2cfdc669
commit 12aef22f05
2 changed files with 35 additions and 5 deletions

View File

@ -739,6 +739,8 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
return null;
}
$implementer_param = $implementer_method_storage->params[$i];
$or_null_guide_type = $guide_param->signature_type
? clone $guide_param->signature_type
: null;
@ -748,15 +750,13 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
}
if ($guide_classlike_storage->user_defined
&& (string)$implementer_method_storage->params[$i]->signature_type
!== (string)$guide_param->signature_type
&& (string)$implementer_method_storage->params[$i]->signature_type
!== (string)$or_null_guide_type
&& (string)$implementer_param->signature_type !== (string)$guide_param->signature_type
&& (string)$implementer_param->signature_type !== (string)$or_null_guide_type
) {
if (IssueBuffer::accepts(
new MethodSignatureMismatch(
'Argument ' . ($i + 1) . ' of ' . $cased_implementer_method_id . ' has wrong type \'' .
$implementer_method_storage->params[$i]->signature_type . '\', expecting \'' .
$implementer_param->signature_type . '\', expecting \'' .
$guide_param->signature_type . '\' as defined by ' .
$cased_guide_method_id,
$implementer_method_storage->params[$i]->location
@ -769,6 +769,22 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
return null;
}
if ($guide_classlike_storage->user_defined && $implementer_param->by_ref !== $guide_param->by_ref) {
if (IssueBuffer::accepts(
new MethodSignatureMismatch(
'Argument ' . ($i + 1) . ' of ' . $cased_implementer_method_id . ' is' .
($implementer_param->by_ref ? '' : ' not') . ' passed by reference, but argument ' .
($i + 1) . ' of ' . $cased_guide_method_id . ' is' . ($guide_param->by_ref ? '' : ' not'),
$implementer_method_storage->params[$i]->location
?: $code_location
)
)) {
return false;
}
return null;
}
$implemeneter_param_type = $implementer_method_storage->params[$i]->type;
if (!$guide_classlike_storage->user_defined &&

View File

@ -245,6 +245,20 @@ class MethodSignatureTest extends TestCase
function foo($bar = null, $bat) : void {}',
'error_message' => 'MisplacedRequiredParam',
],
'clasginByRef' => [
'<?php
class A {
public function foo(string $a) : void {
echo $a;
}
}
class B extends A {
public function foo(string &$a) : void {
echo $a;
}
}',
'error_message' => 'MethodSignatureMismatch',
],
];
}
}