Skip to content

Commit 8c1c8c3

Browse files
committed
Fix binding of T of static when called from a class scope
1 parent e052de4 commit 8c1c8c3

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private static function checkFunctionLikeTypeMatches(
417417
$argument_offset,
418418
!$statements_analyzer->isStatic()
419419
&& (!$method_id || $method_id->method_name !== '__construct')
420-
? $context->self
420+
? ($method_id ? $method_id->fq_class_name : $context->self)
421421
: null,
422422
$context->calling_method_id ?: $context->calling_function_id,
423423
);

tests/Template/FunctionTemplateTest.php

+48-1
Original file line numberDiff line numberDiff line change
@@ -1850,13 +1850,36 @@ class FilterControls extends FilterBase {
18501850
);
18511851
18521852
$test = $list->sortByArr(
1853-
/**
1853+
/**
18541854
* @return list{0: mixed, 1: mixed}
18551855
*/
18561856
static fn ($item): array => [$item, $item],
18571857
1,
18581858
);',
18591859
],
1860+
'staticScope#11368' => [
1861+
'code' => '<?php
1862+
abstract class Uuid
1863+
{
1864+
/**
1865+
* @template T of static
1866+
* @param T $uuid
1867+
*/
1868+
final public function equals($uuid): void {}
1869+
}
1870+
1871+
class UserId1 extends Uuid {}
1872+
class UserId2 extends Uuid {}
1873+
1874+
class User
1875+
{
1876+
public function equals(self $user): void
1877+
{
1878+
(new UserId1())->equals(new UserId1());
1879+
}
1880+
}
1881+
',
1882+
],
18601883
];
18611884
}
18621885

@@ -2477,6 +2500,30 @@ function test1(BType $_value): void {}
24772500
function test2(BType $_value): void {}',
24782501
'error_message' => 'InvalidTemplateParam',
24792502
],
2503+
'staticScope#11368' => [
2504+
'code' => '<?php
2505+
abstract class Uuid
2506+
{
2507+
/**
2508+
* @template T of static
2509+
* @param T $uuid
2510+
*/
2511+
final public function equals($uuid): void {}
2512+
}
2513+
2514+
class UserId1 extends Uuid {}
2515+
class UserId2 extends Uuid {}
2516+
2517+
class User
2518+
{
2519+
public function equals(self $user): void
2520+
{
2521+
(new UserId1())->equals(new UserId2());
2522+
}
2523+
}
2524+
',
2525+
'error_message' => 'ArgumentTypeCoercion',
2526+
],
24802527
];
24812528
}
24822529
}

0 commit comments

Comments
 (0)