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:
parent
2ebf97b4cb
commit
18931295c4
@ -88,7 +88,7 @@ class TemplateStandinTypeReplacer
|
||||
}
|
||||
|
||||
if (!$atomic_types) {
|
||||
throw new \UnexpectedValueException('Cannot remove all keys');
|
||||
return $union_type;
|
||||
}
|
||||
|
||||
if (count($atomic_types) > 1) {
|
||||
|
@ -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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user