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: #10080 #10228

Merged
merged 1 commit into from
Oct 16, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Psalm/Internal/Diff/ClassStatementsDiffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Psalm\Internal\Diff;

use PhpParser;
use UnexpectedValueException;

use function count;
use function get_class;
use function is_string;
use function strpos;
use function strtolower;
use function substr;
Expand Down Expand Up @@ -230,7 +232,19 @@ static function (
/** @var PhpParser\Node */
$affected_elem = $diff_elem->type === DiffElem::TYPE_REMOVE ? $diff_elem->old : $diff_elem->new;
if ($affected_elem instanceof PhpParser\Node\Stmt\ClassMethod) {
$add_or_delete[] = $name_lc . '::' . strtolower((string) $affected_elem->name);
$method_name = strtolower((string) $affected_elem->name);
$add_or_delete[] = $name_lc . '::' . $method_name;
if ($method_name === '__construct') {
foreach ($affected_elem->getParams() as $param) {
if (!$param->flags || !$param->var instanceof PhpParser\Node\Expr\Variable) {
continue;
}
if ($param->var instanceof PhpParser\Node\Expr\Error || !is_string($param->var->name)) {
throw new UnexpectedValueException('Not expecting param name to be non-string');
}
$add_or_delete[] = $name_lc . '::$' . $param->var->name;
}
}
} elseif ($affected_elem instanceof PhpParser\Node\Stmt\Property) {
foreach ($affected_elem->props as $prop) {
$add_or_delete[] = $name_lc . '::$' . $prop->name;
Expand Down
46 changes: 46 additions & 0 deletions tests/Cache/CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,51 @@ public function foo($baz): void
],
],
];

yield 'constructorPropertyPromotionChange' => [
[
[
'files' => [
'/src/A.php' => <<<'PHP'
<?php
class A {
public function __construct(private string $foo)
{
}
public function bar(): string
{
return $this->foo;
}
}
PHP,
],
'issues' => [],
],
[
'files' => [
'/src/A.php' => <<<'PHP'
<?php
class A
{
public function __construct()
{
}
public function bar(): string
{
return $this->foo;
}
}
PHP,
],
'issues' => [
'/src/A.php' => [
"UndefinedThisPropertyFetch: Instance property A::\$foo is not defined",
"MixedReturnStatement: Could not infer a return type",
"MixedInferredReturnType: Could not verify return type 'string' for A::bar",
],
],
],
],
];
}
}
Loading