Skip to content

Commit

Permalink
Consider a property type change as a signature change
Browse files Browse the repository at this point in the history
  • Loading branch information
tscni committed Jun 24, 2023
1 parent 703a4b4 commit 7f9f83e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Psalm/Internal/Diff/ClassStatementsDiffer.php
Expand Up @@ -158,6 +158,22 @@ static function (
return false;
}

if ($a->type xor $b->type) {
return false;
}

if ($a->type) {
$a_type_start = $a->type->getAttribute('startFilePos');

Check failure on line 166 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

MixedAssignment

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:166:25: MixedAssignment: Unable to determine the type that $a_type_start is being assigned to (see https://psalm.dev/032)
$a_type_end = $a->type->getAttribute('endFilePos');

Check failure on line 167 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

MixedAssignment

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:167:25: MixedAssignment: Unable to determine the type that $a_type_end is being assigned to (see https://psalm.dev/032)
$b_type_start = $b->type->getAttribute('startFilePos');

Check failure on line 168 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

MixedAssignment

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:168:25: MixedAssignment: Unable to determine the type that $b_type_start is being assigned to (see https://psalm.dev/032)

Check failure on line 168 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

PossiblyNullReference

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:168:51: PossiblyNullReference: Cannot call method getAttribute on possibly null value (see https://psalm.dev/083)
$b_type_end = $b->type->getAttribute('endFilePos');

Check failure on line 169 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

MixedAssignment

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:169:25: MixedAssignment: Unable to determine the type that $b_type_end is being assigned to (see https://psalm.dev/032)
if (substr($a_code, $a_type_start, $a_type_end - $a_type_start + 1)

Check failure on line 170 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

MixedArgument

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:170:45: MixedArgument: Argument 2 of substr cannot be mixed, expecting int (see https://psalm.dev/030)

Check failure on line 170 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

MixedOperand

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:170:60: MixedOperand: Left operand cannot be mixed (see https://psalm.dev/059)

Check failure on line 170 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

MixedArgument

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:170:60: MixedArgument: Argument 3 of substr cannot be mixed, expecting int|null (see https://psalm.dev/030)
!== substr($b_code, $b_type_start, $b_type_end - $b_type_start + 1)

Check failure on line 171 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

MixedArgument

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:171:49: MixedArgument: Argument 2 of substr cannot be mixed, expecting int (see https://psalm.dev/030)

Check failure on line 171 in src/Psalm/Internal/Diff/ClassStatementsDiffer.php

View workflow job for this annotation

GitHub Actions / build

MixedOperand

src/Psalm/Internal/Diff/ClassStatementsDiffer.php:171:64: MixedOperand: Left operand cannot be mixed (see https://psalm.dev/059)
) {
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 {
Expand Down
19 changes: 19 additions & 0 deletions tests/FileDiffTest.php
Expand Up @@ -544,6 +544,25 @@ class A {
[],
[[84, 133]],
],
'propertyTypeChange' => [
'<?php
namespace Foo;
class A {
public string $a;
}',
'<?php
namespace Foo;
class A {
public ?string $a;
}',
[],
[],
['foo\a::$a', 'foo\a::$a'],
[],
[[84, 100]],
],
'addDocblockToFirst' => [
'<?php
namespace Foo;
Expand Down

0 comments on commit 7f9f83e

Please sign in to comment.