1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 12:24:49 +01:00

Fix #4797 - sanitise assertion output of template result

This commit is contained in:
Matt Brown 2020-12-07 19:11:56 -05:00 committed by Daniil Gentili
parent 50611d5b91
commit 7825a71351
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
2 changed files with 28 additions and 0 deletions

View File

@ -870,6 +870,16 @@ class CallAnalyzer
);
}
if ($template_type_map) {
$readonly_template_result = new TemplateResult($template_type_map, $template_type_map);
\Psalm\Internal\Type\TemplateInferredTypeReplacer::replace(
$op_vars_in_scope[$var_id],
$readonly_template_result,
$codebase
);
}
$op_vars_in_scope[$var_id]->from_docblock = true;
foreach ($op_vars_in_scope[$var_id]->getAtomicTypes() as $changed_atomic_type) {

View File

@ -904,7 +904,25 @@ class FunctionTemplateAssertTest extends TestCase
}',
'error_message' => 'RedundantCondition',
],
'dontBleedTemplateTypeInArrayAgain' => [
'<?php
/**
* @psalm-template T
* @psalm-param array<T> $array
* @psalm-assert array<string, T> $array
*/
function isMap(array $array) : void {}
/**
* @param array<string> $arr
*/
function bar(array $arr): void {
isMap($arr);
/** @psalm-trace $arr */
$arr;
}',
'error_message' => 'string, string',
],
];
}
}