From 12aef22f05914bc58c038f48938f888e15dbd763 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 4 Jan 2018 14:01:17 -0500 Subject: [PATCH] Fix issue where byref differences would not be highlighted --- src/Psalm/Checker/FunctionLikeChecker.php | 26 ++++++++++++++++++----- tests/MethodSignatureTest.php | 14 ++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Checker/FunctionLikeChecker.php b/src/Psalm/Checker/FunctionLikeChecker.php index 968e1ad04..ae18863b2 100644 --- a/src/Psalm/Checker/FunctionLikeChecker.php +++ b/src/Psalm/Checker/FunctionLikeChecker.php @@ -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 && diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index cc08e935f..4761d71ba 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -245,6 +245,20 @@ class MethodSignatureTest extends TestCase function foo($bar = null, $bat) : void {}', 'error_message' => 'MisplacedRequiredParam', ], + 'clasginByRef' => [ + ' 'MethodSignatureMismatch', + ], ]; } }