From a1549329064cbc80eca26e34d50efbfd69990631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tinjo=20Sch=C3=B6ni?= <32767367+tscni@users.noreply.github.com> Date: Sat, 24 Jun 2023 04:38:48 +0200 Subject: [PATCH] Consider a property type change as a signature change --- .../Internal/Diff/ClassStatementsDiffer.php | 16 ++++++ tests/FileDiffTest.php | 57 +++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/Psalm/Internal/Diff/ClassStatementsDiffer.php b/src/Psalm/Internal/Diff/ClassStatementsDiffer.php index 686aeb92917..7d465837683 100644 --- a/src/Psalm/Internal/Diff/ClassStatementsDiffer.php +++ b/src/Psalm/Internal/Diff/ClassStatementsDiffer.php @@ -158,6 +158,22 @@ static function ( return false; } + if ($a->type xor $b->type) { + return false; + } + + if ($a->type) { + $a_type_start = (int) $a->type->getAttribute('startFilePos'); + $a_type_end = (int) $a->type->getAttribute('endFilePos'); + $b_type_start = (int) $b->type->getAttribute('startFilePos'); + $b_type_end = (int) $b->type->getAttribute('endFilePos'); + if (substr($a_code, $a_type_start, $a_type_end - $a_type_start + 1) + !== substr($b_code, $b_type_start, $b_type_end - $b_type_start + 1) + ) { + return false; + } + } + $body_change = substr($a_code, $a_comments_end, $a_end - $a_comments_end) !== substr($b_code, $b_comments_end, $b_end - $b_comments_end); } else { diff --git a/tests/FileDiffTest.php b/tests/FileDiffTest.php index 5071174c00f..acc84f404bb 100644 --- a/tests/FileDiffTest.php +++ b/tests/FileDiffTest.php @@ -544,6 +544,63 @@ class A { [], [[84, 133]], ], + 'propertyTypeAddition' => [ + ' [ + ' [ + ' [ '