diff --git a/src/Psalm/Checker/TypeChecker.php b/src/Psalm/Checker/TypeChecker.php index 902fef560..2d74e0223 100644 --- a/src/Psalm/Checker/TypeChecker.php +++ b/src/Psalm/Checker/TypeChecker.php @@ -304,22 +304,19 @@ class TypeChecker } } elseif (count($clause->possibilities) === 1) { // if there's only one active clause, return all the non-negation clause members ORed together - $things_that_can_be_said = implode( - '|', - array_filter( - $possible_types, - /** - * @param string $possible_type - * @return bool - */ - function ($possible_type) { - return $possible_type[0] !== '!'; - } - ) + $things_that_can_be_said = array_filter( + $possible_types, + /** + * @param string $possible_type + * @return bool + */ + function ($possible_type) { + return $possible_type[0] !== '!'; + } ); - if ($things_that_can_be_said) { - $truths[$var] = $things_that_can_be_said; + if ($things_that_can_be_said && count($things_that_can_be_said) === count($possible_types)) { + $truths[$var] = implode('|', $things_that_can_be_said); } } } diff --git a/tests/ScopeTest.php b/tests/ScopeTest.php index 7688cbf5d..b4f166805 100644 --- a/tests/ScopeTest.php +++ b/tests/ScopeTest.php @@ -821,4 +821,28 @@ class ScopeTest extends PHPUnit_Framework_TestCase $context = new Context('somefile.php'); $file_checker->visitAndAnalyzeMethods($context); } + + /** + * @return void + */ + public function testIntstanceOfSubtraction() + { + $stmts = self::$parser->parse('project_checker, $stmts); + $file_checker->visitAndAnalyzeMethods(); + } }