From d845cdf0c5588b6dd1451ab78c307bdc86366e79 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Thu, 20 Jun 2019 08:37:57 -0400 Subject: [PATCH] Fix #1458 by making instanceof static same as === static --- .../Analyzer/Statements/Expression/AssertionFinder.php | 8 ++++++++ tests/TypeReconciliationTest.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index d4a46964a..e24331350 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -63,6 +63,10 @@ class AssertionFinder $var_type = $conditional->expr->inferredType ?? null; foreach ($instanceof_types as $instanceof_type) { + if ($instanceof_type[0] === '=') { + $instanceof_type = substr($instanceof_type, 1); + } + if ($codebase && $var_type && $inside_negation @@ -1873,6 +1877,10 @@ class AssertionFinder } elseif ($this_class_name && (in_array(strtolower($stmt->class->parts[0]), ['self', 'static'], true)) ) { + if ($stmt->class->parts[0] === 'static') { + return ['=' . $this_class_name]; + } + return [$this_class_name]; } } elseif (isset($stmt->class->inferredType)) { diff --git a/tests/TypeReconciliationTest.php b/tests/TypeReconciliationTest.php index b7a7ec1ee..6a17e0fed 100644 --- a/tests/TypeReconciliationTest.php +++ b/tests/TypeReconciliationTest.php @@ -1355,6 +1355,14 @@ class TypeReconciliationTest extends TestCase $a->foo(); }', ], + 'instanceofStatic' => [ + '