1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-29 20:28:59 +01:00

Fix #4945 - use assertion string for scalar templated assertions

This commit is contained in:
Matt Brown 2021-01-07 10:27:35 -05:00 committed by Daniil Gentili
parent 31be6212b7
commit 4c5c32bc93
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 18 additions and 1 deletions

View File

@ -721,7 +721,7 @@ class CallAnalyzer
} elseif ($replacement_atomic_type instanceof Type\Atomic\TNamedObject) {
$ored_type_assertions[] = $prefix . $replacement_atomic_type->value;
} elseif ($replacement_atomic_type instanceof Type\Atomic\Scalar) {
$ored_type_assertions[] = $prefix . $replacement_atomic_type->getId();
$ored_type_assertions[] = $prefix . $replacement_atomic_type->getAssertionString();
} elseif ($replacement_atomic_type instanceof Type\Atomic\TNull) {
$ored_type_assertions[] = $prefix . 'null';
} elseif ($replacement_atomic_type instanceof Type\Atomic\TTemplateParam) {

View File

@ -715,6 +715,23 @@ class FunctionTemplateAssertTest extends TestCase
return $value;
}'
],
'noCrashOnListKeyAssertion' => [
'<?php
/**
* @template T
* @param T $t
* @param mixed $other
* @psalm-assert =T $other
*/
function assertSame($t, $other) : void {}
/** @param list<int> $list */
function takesList(array $list) : void {
foreach ($list as $i => $l) {
assertSame($i, $l);
}
}'
],
];
}