1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix #5073 — don’t crash when templates cannot be resolved

This commit is contained in:
Matthew Brown 2021-05-13 16:55:22 -04:00
parent 2ebf97b4cb
commit 18931295c4
2 changed files with 25 additions and 2 deletions

View File

@ -88,7 +88,7 @@ class TemplateStandinTypeReplacer
}
if (!$atomic_types) {
throw new \UnexpectedValueException('Cannot remove all keys');
return $union_type;
}
if (count($atomic_types) > 1) {

View File

@ -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' => [
'<?php
/**
* @template TCallback as Closure():string
*/
class A {
/** @var TCallback */
private $callback;
/** @param TCallback $callback */
public function __construct(Closure $callback) {
$this->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',
],
];
}
}