diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index 5583040e62b..1b153d46ed3 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -557,7 +557,11 @@ public function start(PhpParser\Node\FunctionLike $stmt, bool $fake_method = fal = $classlike_storage->appearing_method_ids[$method_name_lc] = $method_id; - if (!$stmt->isPrivate() || $method_name_lc === '__construct' || $classlike_storage->is_trait) { + if (!$stmt->isPrivate() + || $method_name_lc === '__construct' + || $method_name_lc === '__clone' + || $classlike_storage->is_trait + ) { $classlike_storage->inheritable_method_ids[$method_name_lc] = $method_id; } diff --git a/tests/CloneTest.php b/tests/CloneTest.php index de2fa5bda3a..6afe54b5afc 100644 --- a/tests/CloneTest.php +++ b/tests/CloneTest.php @@ -82,6 +82,28 @@ private function __clone() {} clone $a;', 'error_message' => 'InvalidClone', ], + 'notVisibleCloneMethodSubClass' => [ + 'code' => ' 'InvalidClone', + ], + 'notVisibleCloneMethodTrait' => [ + 'code' => ' 'InvalidClone', + ], 'invalidGenericClone' => [ 'code' => '