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()) {