From e5c25eae97330a2cc11503c930d13f95a9fbc8e1 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 20 Jun 2017 15:38:32 -0400 Subject: [PATCH] Fix #172 - make sure new coalesce vars escape brackets --- src/Psalm/Checker/Statements/ExpressionChecker.php | 8 ++++++++ tests/Php70Test.php | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Checker/Statements/ExpressionChecker.php b/src/Psalm/Checker/Statements/ExpressionChecker.php index 0e43bb906..7de187e58 100644 --- a/src/Psalm/Checker/Statements/ExpressionChecker.php +++ b/src/Psalm/Checker/Statements/ExpressionChecker.php @@ -968,6 +968,14 @@ class ExpressionChecker return false; } + foreach ($t_if_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); + } else { + $context->vars_in_scope[$var_id] = $type; + } + } + if ($context->collect_references) { $context->referenced_vars = array_merge( $context->referenced_vars, diff --git a/tests/Php70Test.php b/tests/Php70Test.php index 8bbdab736..4da371aac 100644 --- a/tests/Php70Test.php +++ b/tests/Php70Test.php @@ -60,10 +60,10 @@ class Php70Test extends TestCase ], 'nullCoalesceWithReference' => [ ' [ - ['string|null' => '$a'], + ['int' => '$a'], ], ], 'spaceship' => [