1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +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
parent 0e17a3354f
commit 603ecadbb7
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);
}
}'
],
];
}