diff --git a/src/Psalm/Internal/Diff/FileStatementsDiffer.php b/src/Psalm/Internal/Diff/FileStatementsDiffer.php index 797b6f730..665cb47ca 100644 --- a/src/Psalm/Internal/Diff/FileStatementsDiffer.php +++ b/src/Psalm/Internal/Diff/FileStatementsDiffer.php @@ -115,7 +115,11 @@ class FileStatementsDiffer extends AstDiffer $b_code, ); - $keep = [...$keep, ...$class_keep[0]]; + if ($diff_elem->old->getDocComment() === $diff_elem->new->getDocComment()) { + $keep = [...$keep, ...$class_keep[0]]; + } else { + $keep_signature = [...$keep_signature, ...$class_keep[0]]; + } $keep_signature = [...$keep_signature, ...$class_keep[1]]; $add_or_delete = [...$add_or_delete, ...$class_keep[2]]; $diff_map = [...$diff_map, ...$class_keep[3]]; diff --git a/stubs/CoreGenericFunctions.phpstub b/stubs/CoreGenericFunctions.phpstub index 89b18d0a4..793150fbd 100644 --- a/stubs/CoreGenericFunctions.phpstub +++ b/stubs/CoreGenericFunctions.phpstub @@ -1292,7 +1292,7 @@ function preg_quote(string $str, ?string $delimiter = null) : string {} /** * @psalm-pure * - * @param string|int|float $values + * @param string|stringable-object|int|float $values * @return (PHP_MAJOR_VERSION is 8 ? string : string|false) * @psalm-ignore-falsable-return * diff --git a/tests/Cache/CacheTest.php b/tests/Cache/CacheTest.php index 0efce1c68..04f44eda6 100644 --- a/tests/Cache/CacheTest.php +++ b/tests/Cache/CacheTest.php @@ -199,5 +199,54 @@ class CacheTest extends TestCase ], ], ]; + + yield 'classDocblockChange' => [ + [ + [ + 'files' => [ + '/src/A.php' => <<<'PHP' + [], + ], + [ + 'files' => [ + '/src/A.php' => <<<'PHP' + [ + '/src/A.php' => [ + "UndefinedDocblockClass: Docblock-defined class, interface or enum named T does not exist", + ], + ], + ], + ], + ]; } } diff --git a/tests/CoreStubsTest.php b/tests/CoreStubsTest.php index ed3d0b763..b01898970 100644 --- a/tests/CoreStubsTest.php +++ b/tests/CoreStubsTest.php @@ -125,6 +125,18 @@ class CoreStubsTest extends TestCase '$a===' => 'string', ], ]; + yield 'sprintf accepts Stringable values' => [ + 'code' => ' [], + 'ignored_issues' => [], + 'php_version' => '8.0', + ]; yield 'json_encode returns a non-empty-string provided JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE' => [ 'code' => ' 'InvalidArgument', ], - 'implicitCastWithStrictTypesToEchoOrSprintf' => [ - 'code' => ' 'ImplicitToStringCast', - ], 'implicitCast' => [ 'code' => '