Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameter having object type in PHPDoc and only & in the method's definition, used with code having an object calling it's method with itself as an argument for mentioned parameter #10104

Merged
merged 2 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Psalm\IssueBuffer;
use Psalm\Type;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TObject;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Union;

Expand Down Expand Up @@ -412,7 +413,7 @@ public static function analyze(
$types = $class_type->getAtomicTypes();

foreach ($types as $key => &$type) {
if (!$type instanceof TNamedObject) {
if (!$type instanceof TNamedObject && !$type instanceof TObject) {
unset($types[$key]);
} else {
$type = $type->setFromDocblock(false);
Expand Down
11 changes: 11 additions & 0 deletions tests/MethodCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,17 @@ public function method(mixed $value): mixed
'ignored_issues' => [],
'php_version' => '8.0',
],
'phpdocObjectTypeAndReferenceInParameter' => [
'code' => '<?php
class Foo {
/**
* @param object $object
*/
public function bar(&$object): void {}
}
$x = new Foo();
$x->bar($x);',
],
];
}

Expand Down