Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binding of T of static when called from a class scope #11370

Open
wants to merge 1 commit into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
49 changes: 48 additions & 1 deletion tests/Template/FunctionTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '<?php
abstract class Uuid
{
/**
* @template T of self
* @param T $uuid
*/
final public function equals($uuid): void {}
}

class UserId1 extends Uuid {}
class UserId2 extends Uuid {}

class User
{
public function equals(self $user): void
{
(new UserId1())->equals(new UserId1());
}
}
',
],
];
}

Expand Down Expand Up @@ -2477,6 +2500,30 @@ function test1(BType $_value): void {}
function test2(BType $_value): void {}',
'error_message' => 'InvalidTemplateParam',
],
'staticScope#11368' => [
'code' => '<?php
abstract class Uuid
{
/**
* @template T of static
* @param T $uuid
*/
final public function equals($uuid): void {}
}

class UserId1 extends Uuid {}
class UserId2 extends Uuid {}

class User
{
public function equals(self $user): void
{
(new UserId1())->equals(new UserId2());
}
}
',
'error_message' => 'ArgumentTypeCoercion',
],
];
}
}
Loading