diff --git a/src/Psalm/Checker/MethodChecker.php b/src/Psalm/Checker/MethodChecker.php index 8ad4752f9..75fd18e01 100644 --- a/src/Psalm/Checker/MethodChecker.php +++ b/src/Psalm/Checker/MethodChecker.php @@ -126,19 +126,7 @@ class MethodChecker extends FunctionLikeChecker $storage = self::getStorage($project_checker, $method_id); - if ($storage->return_type) { - return $storage->returns_by_ref; - } - - $class_storage = $project_checker->classlike_storage_provider->get($fq_class_name); - - foreach ($class_storage->overridden_method_ids[$method_name] as $overridden_method_id) { - $overridden_storage = self::getStorage($project_checker, $overridden_method_id); - - return $overridden_storage->returns_by_ref; - } - - return false; + return $storage->returns_by_ref; } /** diff --git a/src/Psalm/Checker/Statements/Expression/CallChecker.php b/src/Psalm/Checker/Statements/Expression/CallChecker.php index bf15c0319..db582ae5e 100644 --- a/src/Psalm/Checker/Statements/Expression/CallChecker.php +++ b/src/Psalm/Checker/Statements/Expression/CallChecker.php @@ -1127,7 +1127,11 @@ class CallChecker $stmt->inferredType = $return_type; - if ($returns_by_ref && $stmt->inferredType && !$stmt->inferredType->by_ref) { + if ($returns_by_ref) { + if (!$stmt->inferredType) { + $stmt->inferredType = Type::getMixed(); + } + $stmt->inferredType->by_ref = $returns_by_ref; } } diff --git a/src/Psalm/Visitor/DependencyFinderVisitor.php b/src/Psalm/Visitor/DependencyFinderVisitor.php index 8eb0339cb..359d59f12 100644 --- a/src/Psalm/Visitor/DependencyFinderVisitor.php +++ b/src/Psalm/Visitor/DependencyFinderVisitor.php @@ -743,7 +743,6 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P ); if ($stmt->returnsByRef()) { - $storage->returns_by_ref = true; $storage->return_type->by_ref = true; } @@ -751,6 +750,10 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P $storage->signature_return_type_location = $storage->return_type_location; } + if ($stmt->returnsByRef()) { + $storage->returns_by_ref = true; + } + $doc_comment = $stmt->getDocComment(); if (!$doc_comment) { @@ -907,8 +910,7 @@ class DependencyFinderVisitor extends PhpParser\NodeVisitorAbstract implements P $storage->return_type->ignore_nullable_issues = true; } - if ($storage->return_type && $stmt->returnsByRef()) { - $storage->returns_by_ref = true; + if ($stmt->returnsByRef() && $storage->return_type) { $storage->return_type->by_ref = true; }