Skip to content

Commit

Permalink
Restore support for null coalesce on match expressions
Browse files Browse the repository at this point in the history
vimeo#10068 added isset restrictions that didn't consider null coalesces on match expressions.
This restores that support by converting the match expression to a virtual variable for the isset analysis, similar to other incompatible expressions.
  • Loading branch information
tscni committed Nov 29, 2023
1 parent 982f95c commit d91aab1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Expand Up @@ -39,6 +39,7 @@ public static function analyze(
|| $root_expr instanceof PhpParser\Node\Expr\MethodCall
|| $root_expr instanceof PhpParser\Node\Expr\StaticCall
|| $root_expr instanceof PhpParser\Node\Expr\Cast
|| $root_expr instanceof PhpParser\Node\Expr\Match_
|| $root_expr instanceof PhpParser\Node\Expr\NullsafePropertyFetch
|| $root_expr instanceof PhpParser\Node\Expr\NullsafeMethodCall
|| $root_expr instanceof PhpParser\Node\Expr\Ternary
Expand Down
15 changes: 15 additions & 0 deletions tests/MatchTest.php
Expand Up @@ -167,6 +167,21 @@ function process(Obj1|Obj2 $obj): int|string
'ignored_issues' => [],
'php_version' => '8.0',
],
'nullCoalesce' => [
'code' => <<<'PHP'
<?php
function foo(): bool { return false; }
$match = match (foo()) {
false => null,
true => 1,
} ?? 2;
PHP,
'assertions' => [
'$match' => 'int',
],
'ignored_issues' => [],
'php_version' => '8.0',
],
];
}

Expand Down

0 comments on commit d91aab1

Please sign in to comment.