From 8910e4226c639f2b7cf7c531c645659855b24946 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Fri, 7 Apr 2017 00:19:55 -0400 Subject: [PATCH] Allow scalar type refinement --- src/Psalm/Checker/TypeChecker.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Psalm/Checker/TypeChecker.php b/src/Psalm/Checker/TypeChecker.php index d14c173cb..5c11586d9 100644 --- a/src/Psalm/Checker/TypeChecker.php +++ b/src/Psalm/Checker/TypeChecker.php @@ -340,6 +340,20 @@ class TypeChecker } } + if ($new_var_type === 'scalar') { + $scalar_types = []; + + foreach ($existing_var_type->types as $type) { + if ($type instanceof Scalar) { + $scalar_types[] = $type; + } + } + + if ($scalar_types) { + return new Type\Union($scalar_types); + } + } + $new_type = Type::parseString($new_var_type); if ($existing_var_type->isMixed()) {