Skip to content

Commit

Permalink
Allow parameter types to be contained by a class template type (#8731)
Browse files Browse the repository at this point in the history
* Allow parameter types to be contained by a class template type in function calls

* Specify PHP version of tests

* Fix tests
  • Loading branch information
danog committed Nov 23, 2022
1 parent f846906 commit 54db596
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
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

0 comments on commit 54db596

Please sign in to comment.