diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index ba01c50b1..9593a332b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -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) { diff --git a/tests/Template/FunctionTemplateAssertTest.php b/tests/Template/FunctionTemplateAssertTest.php index 184aab4bb..98dac0c9f 100644 --- a/tests/Template/FunctionTemplateAssertTest.php +++ b/tests/Template/FunctionTemplateAssertTest.php @@ -904,7 +904,25 @@ class FunctionTemplateAssertTest extends TestCase }', 'error_message' => 'RedundantCondition', ], + 'dontBleedTemplateTypeInArrayAgain' => [ + ' $array + * @psalm-assert array $array + */ + function isMap(array $array) : void {} + /** + * @param array $arr + */ + function bar(array $arr): void { + isMap($arr); + /** @psalm-trace $arr */ + $arr; + }', + 'error_message' => 'string, string', + ], ]; } }