From 1173dcc6a2c14e683db73db15868d4da6139a7f6 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 28 Nov 2017 17:42:00 -0500 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20stop=20reconciling=20types=20wh?= =?UTF-8?q?en=20encountering=20problem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Checker/Statements/Block/IfChecker.php | 28 ------------------- src/Psalm/Checker/TypeChecker.php | 5 ++-- tests/PropertyTypeTest.php | 22 +++++++++++++++ 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/Psalm/Checker/Statements/Block/IfChecker.php b/src/Psalm/Checker/Statements/Block/IfChecker.php index f4f331c10..d3ac145dc 100644 --- a/src/Psalm/Checker/Statements/Block/IfChecker.php +++ b/src/Psalm/Checker/Statements/Block/IfChecker.php @@ -160,10 +160,6 @@ class IfChecker $statements_checker->getSuppressedIssues() ); - if ($if_vars_in_scope_reconciled === false) { - return false; - } - $if_context->vars_in_scope = $if_vars_in_scope_reconciled; $if_context->vars_possibly_in_scope = array_merge( $reconcilable_if_types, @@ -201,10 +197,6 @@ class IfChecker $statements_checker->getSuppressedIssues() ); - if ($else_vars_reconciled === false) { - return false; - } - $temp_else_context->vars_in_scope = $else_vars_reconciled; } @@ -472,10 +464,6 @@ class IfChecker ); } - if ($outer_context_vars_reconciled === false) { - return false; - } - $outer_context->vars_in_scope = $outer_context_vars_reconciled; $mic_drop = true; } @@ -579,10 +567,6 @@ class IfChecker $statements_checker->getSuppressedIssues() ); - if ($elseif_vars_reconciled === false) { - return false; - } - $elseif_context->vars_in_scope = $elseif_vars_reconciled; if ($changed_var_ids) { @@ -674,10 +658,6 @@ class IfChecker $statements_checker->getSuppressedIssues() ); - if ($elseif_vars_reconciled === false) { - return false; - } - $elseif_context->vars_in_scope = $elseif_vars_reconciled; if ($changed_var_ids) { @@ -820,10 +800,6 @@ class IfChecker $statements_checker->getSuppressedIssues() ); - if ($leaving_vars_reconciled === false) { - return false; - } - $implied_outer_context = clone $elseif_context; $implied_outer_context->vars_in_scope = $leaving_vars_reconciled; @@ -944,10 +920,6 @@ class IfChecker $statements_checker->getSuppressedIssues() ); - if ($else_vars_reconciled === false) { - return false; - } - $else_context->vars_in_scope = $else_vars_reconciled; $else_context->removeReconciledClauses($changed_var_ids); diff --git a/src/Psalm/Checker/TypeChecker.php b/src/Psalm/Checker/TypeChecker.php index 14bd1740f..25947861f 100644 --- a/src/Psalm/Checker/TypeChecker.php +++ b/src/Psalm/Checker/TypeChecker.php @@ -38,7 +38,7 @@ class TypeChecker * @param CodeLocation $code_location * @param array $suppressed_issues * - * @return array|false + * @return array */ public static function reconcileKeyedTypes( array $new_types, @@ -111,7 +111,8 @@ class TypeChecker } if ($result_type_candidate === false) { - return false; + $failed_reconciliation = true; + $result_type_candidate = Type::getMixed(); } $orred_type = $orred_type diff --git a/tests/PropertyTypeTest.php b/tests/PropertyTypeTest.php index f80db3ec7..91baebca2 100644 --- a/tests/PropertyTypeTest.php +++ b/tests/PropertyTypeTest.php @@ -353,6 +353,28 @@ class PropertyTypeTest extends TestCase bar(A::$a[$b]); }', ], + 'staticPropertyArrayIssetAssertionWithVariableOffsetAndElse' => [ + ' */ + public static $a = []; + } + + function foo() : void { + $b = "hello"; + + if (!isset(A::$a[$b])) { + $g = "bar"; + } else { + bar(A::$a[$b]); + $g = "foo"; + } + + bar($g); + }', + ], 'traitConstructor' => [ '