diff --git a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php index 91a3e8acf..a01b5cf66 100644 --- a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php @@ -88,7 +88,7 @@ class TemplateStandinTypeReplacer } if (!$atomic_types) { - throw new \UnexpectedValueException('Cannot remove all keys'); + return $union_type; } if (count($atomic_types) > 1) { diff --git a/tests/Template/ClassTemplateTest.php b/tests/Template/ClassTemplateTest.php index 2c1d1596a..2a04b8b49 100644 --- a/tests/Template/ClassTemplateTest.php +++ b/tests/Template/ClassTemplateTest.php @@ -3370,7 +3370,7 @@ class ClassTemplateTest extends TestCase $wm[$ex] = 42; } ', - ] + ], ]; } @@ -4010,6 +4010,29 @@ class ClassTemplateTest extends TestCase takesA($child);', 'error_message' => 'InvalidArgument', ], + 'noCrashTemplatedClosure' => [ + 'callback = $callback; + } + + /** @param TCallback $callback */ + public function setCallback(Closure $callback): void { + $this->callback = $callback; + } + } + $a = new A(function() { return "a";}); + $a->setCallback(function() { return "b";});', + 'error_message' => 'InvalidScalarArgument', + ], ]; } }