From 16e89a8c1c8bcac83d62d0b8872e59e2ff1c00da Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Fri, 16 Dec 2016 17:59:27 -0500 Subject: [PATCH] Fix #26 - Allow refinement via type intersection Not just via explict subsets --- src/Psalm/Checker/TypeChecker.php | 4 +++- tests/TypeTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Checker/TypeChecker.php b/src/Psalm/Checker/TypeChecker.php index a16fbb91b..0fbaf9452 100644 --- a/src/Psalm/Checker/TypeChecker.php +++ b/src/Psalm/Checker/TypeChecker.php @@ -1253,7 +1253,9 @@ class TypeChecker return $new_type; } - if (!TypeChecker::isContainedBy($new_type, $existing_var_type) && $code_location) { + if (!TypeChecker::isContainedBy($new_type, $existing_var_type) && + !TypeChecker::isContainedBy($existing_var_type, $new_type) && + $code_location) { if (IssueBuffer::accepts( new TypeDoesNotContainType( 'Cannot resolve types for ' . $key . ' - ' . $existing_var_type . ' does not contain ' . $new_type, diff --git a/tests/TypeTest.php b/tests/TypeTest.php index 61bfb5c95..59b513adb 100644 --- a/tests/TypeTest.php +++ b/tests/TypeTest.php @@ -1660,4 +1660,19 @@ class TypeTest extends PHPUnit_Framework_TestCase $context = new Context('somefile.php'); $file_checker->check(); } + + public function testTypeRefinementWithIsNumeric() + { + $stmts = self::$parser->parse('check(); + } }