1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #5219 - invalidate cache for changed params

This commit is contained in:
Matt Brown 2021-02-14 12:07:09 -05:00
parent a80d5b736b
commit 8834a54934
3 changed files with 187 additions and 4 deletions

View File

@ -970,7 +970,8 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
false,
false,
$this->function instanceof ClassMethod
&& strtolower($this->function->name->name) !== '__construct'
&& strtolower($this->function->name->name) !== '__construct',
$context->calling_method_id
) === false) {
$check_stmts = false;
}

View File

@ -862,6 +862,178 @@ class TemporaryUpdateTest extends \Psalm\Tests\TestCase
],
'error_positions' => [[196], []],
],
'changeUseShouldInvalidateBadReturn' => [
[
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Baz\B;
class A {
public function foo() : ?B {
return null;
}
}
}
namespace Bar {
class B {}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Bar\B;
class A {
public function foo() : ?B {
return null;
}
}
}
namespace Bar {
class B {}
}',
],
],
'error_positions' => [[196], []],
],'changeUseShouldInvalidateBadDocblockReturn' => [
[
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Baz\B;
class A {
/** @return ?B */
public function foo() {
return null;
}
}
}
namespace Bar {
class B {}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Bar\B;
class A {
/** @return ?B */
public function foo() {
return null;
}
}
}
namespace Bar {
class B {}
}',
],
],
'error_positions' => [[184], []],
],
'changeUseShouldInvalidateBadParam' => [
[
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Baz\B;
class A {
public function foo(B $b) : void {}
}
}
namespace Bar {
class B {}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Bar\B;
class A {
public function foo(B $b) : void {}
}
}
namespace Bar {
class B {}
}',
],
],
'error_positions' => [[192], []],
],
'changeUseShouldInvalidateBadDocblockParam' => [
[
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Baz\B;
class A {
/** @param B $b */
public function foo($b) : void {}
}
}
namespace Bar {
class B {}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Bar\B;
class A {
/** @param B $b */
public function foo($b) : void {}
}
}
namespace Bar {
class B {}
}',
],
],
'error_positions' => [[183], []],
],
'changeUseShouldInvalidateBadParam' => [
[
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Baz\B;
class A extends B {}
}
namespace Bar {
class B {}
}',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo {
use Bar\B;
class A extends B {}
}
namespace Bar {
class B {}
}',
],
],
'error_positions' => [[142], []],
],
'fixMissingProperty' => [
[
[

View File

@ -1511,14 +1511,24 @@ class FunctionTemplateTest extends TestCase
'isArrayCheckOnTemplated' => [
'<?php
/**
* @psalm-pure
* @template TIterable of iterable
*/
function toList(iterable $iterable): void
{
function toList(iterable $iterable): void {
if (is_array($iterable)) {}
}'
],
'transformNestedTemplateWherePossible' => [
'<?php
/**
* @template TValue
* @template TArray of non-empty-array<TValue>
* @param TArray $arr
* @return TValue
*/
function toList(array $arr): array {
return reset($arr);
}'
],
];
}