Skip to content

Commit

Permalink
Prevent mixed|null when function param is mixed with a null default v…
Browse files Browse the repository at this point in the history
…alue
  • Loading branch information
robchett committed Feb 7, 2024
1 parent 4a5dbca commit 8f8e539
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,9 @@ private function getTranslatedFunctionParam(
$this->codebase->analysis_php_version_id,
);

if ($is_nullable) {
if ($param_type->isMixed()) {
$is_nullable = true;
} elseif ($is_nullable) {
$param_type = $param_type->getBuilder()->addType(new TNull)->freeze();
} else {
$is_nullable = $param_type->isNullable();
Expand Down
14 changes: 14 additions & 0 deletions tests/ArgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,20 @@ function foo($a, ...$b) {}
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',
],
];
}

Expand Down

0 comments on commit 8f8e539

Please sign in to comment.