mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #783 - allow ternarys to declare vars
This commit is contained in:
parent
6ecea35837
commit
dda9b4e48c
@ -151,10 +151,24 @@ class TernaryChecker
|
||||
|
||||
foreach ($t_else_context->vars_in_scope as $var_id => $type) {
|
||||
if (isset($context->vars_in_scope[$var_id])) {
|
||||
$context->vars_in_scope[$var_id] = Type::combineUnionTypes($context->vars_in_scope[$var_id], $type);
|
||||
$context->vars_in_scope[$var_id] = Type::combineUnionTypes(
|
||||
$context->vars_in_scope[$var_id],
|
||||
$type
|
||||
);
|
||||
} elseif (isset($t_if_context->vars_in_scope[$var_id])) {
|
||||
$context->vars_in_scope[$var_id] = Type::combineUnionTypes(
|
||||
$t_if_context->vars_in_scope[$var_id],
|
||||
$type
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$context->vars_possibly_in_scope = array_merge(
|
||||
$context->vars_possibly_in_scope,
|
||||
$t_if_context->vars_possibly_in_scope,
|
||||
$t_else_context->vars_possibly_in_scope
|
||||
);
|
||||
|
||||
$context->referenced_var_ids = array_merge(
|
||||
$context->referenced_var_ids,
|
||||
$t_else_context->referenced_var_ids
|
||||
|
@ -120,6 +120,11 @@ class BinaryOperationTest extends TestCase
|
||||
'$d' => 'bool',
|
||||
],
|
||||
],
|
||||
'ternaryAssignment' => [
|
||||
'<?php
|
||||
rand(0, 1) ? $a = 1 : $a = 2;
|
||||
echo $a;',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user