From d3976ce1c09b28e830ac3ce91b174e5c47aaf2f0 Mon Sep 17 00:00:00 2001 From: robchett Date: Thu, 20 Mar 2025 21:17:42 +0000 Subject: [PATCH] Fix binding of T of static when called from a class scope --- .../Expression/Call/ArgumentAnalyzer.php | 2 +- tests/Template/FunctionTemplateTest.php | 49 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php index a252cdf5c21..42240e0ecc5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php @@ -417,7 +417,7 @@ private static function checkFunctionLikeTypeMatches( $argument_offset, !$statements_analyzer->isStatic() && (!$method_id || $method_id->method_name !== '__construct') - ? $context->self + ? ($method_id ? $method_id->fq_class_name : $context->self) : null, $context->calling_method_id ?: $context->calling_function_id, ); diff --git a/tests/Template/FunctionTemplateTest.php b/tests/Template/FunctionTemplateTest.php index 79a76652842..dc41ddf658d 100644 --- a/tests/Template/FunctionTemplateTest.php +++ b/tests/Template/FunctionTemplateTest.php @@ -1850,13 +1850,36 @@ class FilterControls extends FilterBase { ); $test = $list->sortByArr( - /** + /** * @return list{0: mixed, 1: mixed} */ static fn ($item): array => [$item, $item], 1, );', ], + 'staticScope#11368' => [ + 'code' => 'equals(new UserId1()); + } + } + ', + ], ]; } @@ -2477,6 +2500,30 @@ function test1(BType $_value): void {} function test2(BType $_value): void {}', 'error_message' => 'InvalidTemplateParam', ], + 'staticScope#11368' => [ + 'code' => 'equals(new UserId2()); + } + } + ', + 'error_message' => 'ArgumentTypeCoercion', + ], ]; } }