1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Prevent mixed|null when function param is mixed with a null default value

This commit is contained in:
robchett 2024-02-07 20:37:00 +00:00
parent 4a5dbcaebc
commit 5579fd469b
2 changed files with 17 additions and 1 deletions

View File

@ -825,7 +825,9 @@ final class FunctionLikeNodeScanner
$this->codebase->analysis_php_version_id,
);
if ($is_nullable) {
if ($param_type->isMixed()) {
$is_nullable = false;
} elseif ($is_nullable) {
$param_type = $param_type->getBuilder()->addType(new TNull)->freeze();
} else {
$is_nullable = $param_type->isNullable();

View File

@ -355,6 +355,20 @@ class ArgTest extends TestCase
var_caller("foo");',
],
'mixedNullable' => [
'code' => '<?php
class A {
public function __construct(public mixed $default = null) {
}
}
$a = new A;
$_v = $a->default;',
'assertions' => [
'$_v===' => 'mixed',
],
'ignored_issues' => [],
'php_version' => '8.0',
],
];
}