From 772fd496b7f164269674daf0706e886621d23d2f Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Thu, 24 May 2018 12:23:50 -0400 Subject: [PATCH] Fix issue with array_key_exists not having an effect --- src/Psalm/Type/Reconciler.php | 4 +++- tests/RedundantConditionTest.php | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index 6a74dac73..7ee5d9591 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -112,7 +112,9 @@ class Reconciler $has_equality = true; } - $has_isset = $has_isset || $new_type_part_part === 'isset'; + $has_isset = $has_isset + || $new_type_part_part === 'isset' + || $new_type_part_part === 'array-key-exists'; $result_type_candidate = self::reconcileTypes( $new_type_part_part, diff --git a/tests/RedundantConditionTest.php b/tests/RedundantConditionTest.php index b1be5a5bb..21795e2bc 100644 --- a/tests/RedundantConditionTest.php +++ b/tests/RedundantConditionTest.php @@ -423,6 +423,15 @@ class RedundantConditionTest extends TestCase var_export($x); }', ], + 'arrayKeyExistsAccess' => [ + ' $arr */ + function foo(array $arr) : void { + if (array_key_exists(1, $arr)) { + $a = ($arr[1] === "b") ? true : false; + } + }', + ], ]; }