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

Allow parameter types to be contained by a class template type #8731

Merged
merged 3 commits into from Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1096,10 +1096,6 @@ public static function checkTemplateResult(
$statements_analyzer->getCodebase(),
$lower_bound->type,
$bound_with_equality->type
) && UnionTypeComparator::isContainedBy(
$statements_analyzer->getCodebase(),
$bound_with_equality->type,
$lower_bound->type
)) {
continue 2;
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Template/FunctionTemplateTest.php
Expand Up @@ -1621,6 +1621,47 @@ function foo(?float $p): ?float
return $p - 1;
}'
],
'literalIsAlwaysContainedInString' => [
'code' => '<?php
/**
* @template T
*/
interface Norm
{
/**
* @param T $input
* @return T
*/
public function normalize(mixed $input): mixed;
}

/**
* @implements Norm<string>
*/
class StringNorm implements Norm
{
public function normalize(mixed $input): mixed
{
return strtolower($input);
}
}

/**
* @template TNorm
*
* @param TNorm $value
* @param Norm<TNorm> $n
*/
function normalizeField(mixed $value, Norm $n): void
{
$n->normalize($value);
}

normalizeField("foo", new StringNorm());',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.0'
]
];
}

Expand Down