Skip to content

Commit

Permalink
Fix #2464 - null coalesce shouldn’t allow undefined vars
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Dec 13, 2019
1 parent 6ff312f commit ca5f8fa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -586,7 +586,11 @@ function (\Psalm\Internal\Clause $c) use ($mixed_var_ids) {
new CodeLocation($statements_analyzer->getSource(), $stmt->left)
);

$t_if_context->vars_in_scope = $t_if_vars_in_scope_reconciled;
foreach ($context->vars_in_scope as $var_id => $_) {
if (isset($t_if_vars_in_scope_reconciled[$var_id])) {
$t_if_context->vars_in_scope[$var_id] = $t_if_vars_in_scope_reconciled[$var_id];
}
}
}

if (!self::hasArrayDimFetch($stmt->left)) {
Expand Down
10 changes: 10 additions & 0 deletions tests/TypeReconciliation/IssetTest.php
Expand Up @@ -744,6 +744,16 @@ function foo(string $s) : string {
}',
'error_message' => 'NullableReturnStatement',
],
'undefinedVarInNullCoalesce' => [
'<?php
function bar(): void {
$do_baz = $config["do_it"] ?? false;
if ($do_baz) {
baz();
}
}',
'UndefinedVariable'
],
];
}
}

0 comments on commit ca5f8fa

Please sign in to comment.