1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

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

* Allow parameter types to be contained by a class template type in function calls

* Specify PHP version of tests

* Fix tests
This commit is contained in:
Daniil Gentili 2022-11-23 06:14:30 +01:00 committed by GitHub
parent f846906b29
commit 54db59682d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 4 deletions

View File

@ -1096,10 +1096,6 @@ class CallAnalyzer
$statements_analyzer->getCodebase(),
$lower_bound->type,
$bound_with_equality->type
) && UnionTypeComparator::isContainedBy(
$statements_analyzer->getCodebase(),
$bound_with_equality->type,
$lower_bound->type
)) {
continue 2;
}

View File

@ -1621,6 +1621,47 @@ class FunctionTemplateTest extends TestCase
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'
]
];
}