diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php index e5fc9f588..7c983bbe3 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php @@ -907,13 +907,15 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\ } } + $generic_params = $template_result->generic_params; + if ($method_storage->assertions) { self::applyAssertionsToContext( $stmt->name, null, $method_storage->assertions, $stmt->args, - $found_generic_params ?: [], + $generic_params, $context, $statements_analyzer ); @@ -921,8 +923,8 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\ if ($method_storage->if_true_assertions) { $stmt->ifTrueAssertions = array_map( - function (Assertion $assertion) use ($found_generic_params) : Assertion { - return $assertion->getUntemplatedCopy($found_generic_params ?: []); + function (Assertion $assertion) use ($generic_params) : Assertion { + return $assertion->getUntemplatedCopy($generic_params); }, $method_storage->if_true_assertions ); @@ -930,8 +932,8 @@ class StaticCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\ if ($method_storage->if_false_assertions) { $stmt->ifFalseAssertions = array_map( - function (Assertion $assertion) use ($found_generic_params) : Assertion { - return $assertion->getUntemplatedCopy($found_generic_params ?: []); + function (Assertion $assertion) use ($generic_params) : Assertion { + return $assertion->getUntemplatedCopy($generic_params); }, $method_storage->if_false_assertions ); diff --git a/tests/Template/FunctionTemplateAssertTest.php b/tests/Template/FunctionTemplateAssertTest.php index c70905407..abf468f4d 100644 --- a/tests/Template/FunctionTemplateAssertTest.php +++ b/tests/Template/FunctionTemplateAssertTest.php @@ -253,10 +253,40 @@ class FunctionTemplateAssertTest extends TestCase $d = rand(0, 1) ? 4 : null; assertSame(null, $d); - function foo(string $a, string $b) : void { + function assertStringsAreSame(string $a, string $b) : void { + assertSame($a, $b); + } + + /** @param mixed $a */ + function assertMaybeStringsAreSame($a, string $b) : void { + assertSame($a, $b); + } + + /** @param mixed $b */ + function alsoAssertMaybeStringsAreSame(string $a, $b) : void { assertSame($a, $b); }', ], + 'allowCanBeSameAfterStaticMethodAssertion' => [ + ' [ '