From 603ecadbb787dd6378ccbf0aae4a1118bc3fb9c7 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 7 Jan 2021 10:27:35 -0500 Subject: [PATCH] Fix #4945 - use assertion string for scalar templated assertions --- .../Statements/Expression/CallAnalyzer.php | 2 +- tests/Template/FunctionTemplateAssertTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index e326b1c11..ebf915932 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -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) { diff --git a/tests/Template/FunctionTemplateAssertTest.php b/tests/Template/FunctionTemplateAssertTest.php index 98dac0c9f..00613e89b 100644 --- a/tests/Template/FunctionTemplateAssertTest.php +++ b/tests/Template/FunctionTemplateAssertTest.php @@ -715,6 +715,23 @@ class FunctionTemplateAssertTest extends TestCase return $value; }' ], + 'noCrashOnListKeyAssertion' => [ + ' $list */ + function takesList(array $list) : void { + foreach ($list as $i => $l) { + assertSame($i, $l); + } + }' + ], ]; }