Skip to content
Permalink
Browse files

Move Union::getTypes to Union::getAtomicTypes

  • Loading branch information
muglug committed Jan 4, 2020
1 parent ba6d0df commit 9fa2db1b6c4fd0982211ae95ec49a645e50db9a8
Showing with 312 additions and 297 deletions.
  1. +1 −1 examples/plugins/composer-based/echo-checker/EchoChecker.php
  2. +1 −1 src/Psalm/Codebase.php
  3. +1 −1 src/Psalm/Context.php
  4. +1 −1 src/Psalm/Internal/Analyzer/ClassAnalyzer.php
  5. +3 −3 src/Psalm/Internal/Analyzer/FunctionAnalyzer.php
  6. +1 −1 src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php
  7. +2 −2 src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeCollector.php
  8. +1 −1 src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
  9. +1 −1 src/Psalm/Internal/Analyzer/MethodAnalyzer.php
  10. +1 −1 src/Psalm/Internal/Analyzer/Statements/Block/ForAnalyzer.php
  11. +4 −4 src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php
  12. +1 −1 src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php
  13. +1 −1 src/Psalm/Internal/Analyzer/Statements/Block/WhileAnalyzer.php
  14. +9 −6 src/Psalm/Internal/Analyzer/Statements/Expression/ArrayAnalyzer.php
  15. +9 −9 src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php
  16. +6 −6 src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/ArrayAssignmentAnalyzer.php
  17. +2 −2 src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/PropertyAssignmentAnalyzer.php
  18. +2 −2 src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php
  19. +4 −4 src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php
  20. +2 −2 src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php
  21. +5 −5 src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php
  22. +4 −4 src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php
  23. +4 −4 src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php
  24. +24 −24 src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php
  25. +13 −13 src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php
  26. +1 −1 src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php
  27. +5 −5 src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/PropertyFetchAnalyzer.php
  28. +13 −13 src/Psalm/Internal/Analyzer/Statements/ExpressionAnalyzer.php
  29. +4 −2 src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php
  30. +2 −2 src/Psalm/Internal/Analyzer/Statements/ThrowAnalyzer.php
  31. +3 −3 src/Psalm/Internal/Analyzer/StatementsAnalyzer.php
  32. +23 −23 src/Psalm/Internal/Analyzer/TypeAnalyzer.php
  33. +1 −1 src/Psalm/Internal/Codebase/CallMap.php
  34. +2 −2 src/Psalm/Internal/Codebase/ClassLikes.php
  35. +1 −1 src/Psalm/Internal/Codebase/Functions.php
  36. +3 −3 src/Psalm/Internal/Codebase/Methods.php
  37. +3 −3 src/Psalm/Internal/Codebase/Populator.php
  38. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayChunkReturnTypeProvider.php
  39. +4 −4 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayColumnReturnTypeProvider.php
  40. +2 −2 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php
  41. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMapReturnTypeProvider.php
  42. +5 −5 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayMergeReturnTypeProvider.php
  43. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPadReturnTypeProvider.php
  44. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPointerAdjustmentReturnTypeProvider.php
  45. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php
  46. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayRandReturnTypeProvider.php
  47. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReduceReturnTypeProvider.php
  48. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReverseReturnTypeProvider.php
  49. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArraySliceReturnTypeProvider.php
  50. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayUniqueReturnTypeProvider.php
  51. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayValuesReturnTypeProvider.php
  52. +2 −2 src/Psalm/Internal/Provider/ReturnTypeProvider/FilterVarReturnTypeProvider.php
  53. +1 −1 src/Psalm/Internal/Provider/ReturnTypeProvider/IteratorToArrayReturnTypeProvider.php
  54. +2 −2 src/Psalm/Internal/Scanner/PhpStormMetaScanner.php
  55. +31 −31 src/Psalm/Internal/Type/AssertionReconciler.php
  56. +22 −22 src/Psalm/Internal/Type/NegatedAssertionReconciler.php
  57. +3 −3 src/Psalm/Internal/Type/TypeCombination.php
  58. +14 −14 src/Psalm/Internal/Type/UnionTemplateHandler.php
  59. +12 −12 src/Psalm/Internal/Visitor/ReflectorVisitor.php
  60. +1 −1 src/Psalm/Storage/Assertion.php
  61. +12 −12 src/Psalm/Type.php
  62. +2 −2 src/Psalm/Type/Atomic/CallableTrait.php
  63. +1 −1 src/Psalm/Type/Atomic/HasIntersectionTrait.php
  64. +6 −6 src/Psalm/Type/Reconciler.php
  65. +12 −2 src/Psalm/Type/Union.php
  66. +1 −1 tests/CodebaseTest.php
  67. +1 −1 tests/Config/PluginTest.php
  68. +1 −1 tests/TypeCombinationTest.php
  69. +2 −2 tests/TypeReconciliation/ReconcilerTest.php
@@ -46,7 +46,7 @@ public static function afterStatementAnalysis(
continue;
}

$types = $expr_type->getTypes();
$types = $expr_type->getAtomicTypes();

foreach ($types as $type) {
if ($type instanceof \Psalm\Type\Atomic\TString
@@ -1340,7 +1340,7 @@ public function getCompletionItemsForClassishThing(string $type_string, string $

$type = Type::parseString($type_string);

foreach ($type->getTypes() as $atomic_type) {
foreach ($type->getAtomicTypes() as $atomic_type) {
if ($atomic_type instanceof Type\Atomic\TNamedObject) {
try {
$class_storage = $this->classlike_storage_provider->get($atomic_type->value);
@@ -414,7 +414,7 @@ public function update(
// if the type changed within the block of statements, process the replacement
// also never allow ourselves to remove all types from a union
if ((!$new_type || !$old_type->equals($new_type))
&& ($new_type || count($existing_type->getTypes()) > 1)
&& ($new_type || count($existing_type->getAtomicTypes()) > 1)
) {
$existing_type->substitute($old_type, $new_type);

@@ -1867,7 +1867,7 @@ private function checkTemplateParams(
if (isset($parent_storage->template_covariants[$i])
&& !$parent_storage->template_covariants[$i]
) {
foreach ($extended_type->getTypes() as $t) {
foreach ($extended_type->getAtomicTypes() as $t) {
if ($t instanceof Type\Atomic\TTemplateParam
&& $storage->template_types
&& $storage->template_covariants
@@ -110,7 +110,7 @@ public static function getReturnTypeFromCallMapWithArgs(

case 'count':
if (($first_arg_type = $statements_analyzer->node_data->getType($call_args[0]->value))) {
$atomic_types = $first_arg_type->getTypes();
$atomic_types = $first_arg_type->getAtomicTypes();

if (count($atomic_types) === 1) {
if (isset($atomic_types['array'])) {
@@ -249,7 +249,7 @@ public static function getReturnTypeFromCallMapWithArgs(
if ($first_arg_type = $statements_analyzer->node_data->getType($first_arg)) {
$numeric_types = [];

foreach ($first_arg_type->getTypes() as $inner_type) {
foreach ($first_arg_type->getAtomicTypes() as $inner_type) {
if ($inner_type->isNumericType()) {
$numeric_types[] = $inner_type;
}
@@ -271,7 +271,7 @@ public static function getReturnTypeFromCallMapWithArgs(
if ($first_arg_type = $statements_analyzer->node_data->getType($first_arg)) {
if ($first_arg_type->hasArray()) {
/** @psalm-suppress PossiblyUndefinedStringArrayOffset */
$array_type = $first_arg_type->getTypes()['array'];
$array_type = $first_arg_type->getAtomicTypes()['array'];
if ($array_type instanceof Type\Atomic\ObjectLike) {
return $array_type->getGenericValueType();
}
@@ -673,7 +673,7 @@ public static function checkReturnType(
}

if (!$storage->signature_return_type || $storage->signature_return_type === $storage->return_type) {
foreach ($storage->return_type->getTypes() as $type) {
foreach ($storage->return_type->getAtomicTypes() as $type) {
if ($type instanceof Type\Atomic\TNamedObject
&& 'parent' === $type->value
&& null === $parent_class
@@ -45,7 +45,7 @@ public static function getReturnTypes(
if (!$stmt->expr) {
$return_types[] = new Atomic\TVoid();
} elseif ($stmt_type = $nodes->getType($stmt)) {
$return_types = array_merge(array_values($stmt_type->getTypes()), $return_types);
$return_types = array_merge(array_values($stmt_type->getAtomicTypes()), $return_types);

if ($stmt_type->ignore_nullable_issues) {
$ignore_nullable_issues = true;
@@ -348,7 +348,7 @@ protected static function getYieldTypeFromExpression(
return [new Atomic\TMixed()];
} elseif ($stmt instanceof PhpParser\Node\Expr\YieldFrom) {
if ($stmt_expr_type = $nodes->getType($stmt->expr)) {
return array_values($stmt_expr_type->getTypes());
return array_values($stmt_expr_type->getAtomicTypes());
}

return [new Atomic\TMixed()];
@@ -608,7 +608,7 @@ function (FunctionLikeParameter $p) {
* @psalm-suppress PossiblyUndefinedStringArrayOffset
* @var Type\Atomic\TFn
*/
$closure_atomic = \array_values($function_type->getTypes())[0];
$closure_atomic = \array_values($function_type->getAtomicTypes())[0];
$closure_atomic->return_type = $closure_return_type;
}
}
@@ -1133,7 +1133,7 @@ private static function transformTemplates(
if (is_string($key)) {
$new_bases = [];

foreach ($mapped_type->getTypes() as $mapped_atomic_type) {
foreach ($mapped_type->getAtomicTypes() as $mapped_atomic_type) {
if ($mapped_atomic_type instanceof Type\Atomic\TTemplateParam) {
$new_bases[] = $mapped_atomic_type->defining_class;
}
@@ -88,7 +88,7 @@ public static function analyze(

foreach ($stmt->cond as $cond) {
if ($cond_type = $statements_analyzer->node_data->getType($cond)) {
foreach ($cond_type->getTypes() as $iterator_type) {
foreach ($cond_type->getAtomicTypes() as $iterator_type) {
$always_enters_loop = $iterator_type instanceof Type\Atomic\TTrue;

break;
@@ -418,9 +418,9 @@ public static function checkIteratorType(
$invalid_iterator_types = [];
$raw_object_types = [];

foreach ($iterator_type->getTypes() as $iterator_atomic_type) {
foreach ($iterator_type->getAtomicTypes() as $iterator_atomic_type) {
if ($iterator_atomic_type instanceof Type\Atomic\TTemplateParam) {
$iterator_atomic_type = array_values($iterator_atomic_type->as->getTypes())[0];
$iterator_atomic_type = array_values($iterator_atomic_type->as->getAtomicTypes())[0];
}

// if it's an empty array, we cannot iterate over it
@@ -749,7 +749,7 @@ public static function handleIterable(
$statements_analyzer->node_data = $old_data_provider;

if ($iterator_class_type) {
foreach ($iterator_class_type->getTypes() as $array_atomic_type) {
foreach ($iterator_class_type->getAtomicTypes() as $array_atomic_type) {
$key_type_part = null;
$value_type_part = null;

@@ -1032,7 +1032,7 @@ private static function getExtendedType(

$return_type = null;

foreach ($extended_type->getTypes() as $extended_atomic_type) {
foreach ($extended_type->getAtomicTypes() as $extended_atomic_type) {
if (!$extended_atomic_type instanceof Type\Atomic\TTemplateParam) {
if (!$return_type) {
$return_type = $extended_type;
@@ -303,7 +303,7 @@ private static function handleCase(

$type_statements = [];

foreach ($switch_var_type->getTypes() as $type) {
foreach ($switch_var_type->getAtomicTypes() as $type) {
if ($type instanceof Type\Atomic\GetClassT) {
$type_statements[] = new PhpParser\Node\Expr\FuncCall(
new PhpParser\Node\Name(['get_class']),
@@ -71,7 +71,7 @@ public static function analyze(
if ($stmt_cond_type = $statements_analyzer->node_data->getType($stmt->cond)) {
$always_enters_loop = true;

foreach ($stmt_cond_type->getTypes() as $iterator_type) {
foreach ($stmt_cond_type->getAtomicTypes() as $iterator_type) {
if ($iterator_type instanceof Type\Atomic\TArray
|| $iterator_type instanceof Type\Atomic\ObjectLike
) {
@@ -76,7 +76,7 @@ public static function analyze(
continue;
}

foreach ($unpacked_array_type->getTypes() as $unpacked_atomic_type) {
foreach ($unpacked_array_type->getAtomicTypes() as $unpacked_atomic_type) {
if ($unpacked_atomic_type instanceof Type\Atomic\ObjectLike) {
$unpacked_array_offset = 0;
foreach ($unpacked_atomic_type->properties as $key => $property_value) {
@@ -97,7 +97,7 @@ public static function analyze(
$item_key_atomic_types[] = new Type\Atomic\TLiteralInt($key);
$item_value_atomic_types = array_merge(
$item_value_atomic_types,
array_values($property_value->getTypes())
array_values($property_value->getAtomicTypes())
);
$array_keys[$int_offset + $int_offset_diff + $unpacked_array_offset] = true;
$property_types[$int_offset + $int_offset_diff + $unpacked_array_offset] = $property_value;
@@ -126,14 +126,14 @@ public static function analyze(

$item_value_atomic_types = array_merge(
$item_value_atomic_types,
array_values($unpacked_atomic_type->type_params[1]->getTypes())
array_values($unpacked_atomic_type->type_params[1]->getAtomicTypes())
);
} elseif ($unpacked_atomic_type instanceof Type\Atomic\TList) {
$item_key_atomic_types[] = new Type\Atomic\TInt();

$item_value_atomic_types = array_merge(
$item_value_atomic_types,
array_values($unpacked_atomic_type->type_param->getTypes())
array_values($unpacked_atomic_type->type_param->getAtomicTypes())
);
}
}
@@ -164,7 +164,10 @@ public static function analyze(
$key_type = Type::getInt(false, (int) $item->key->value);
}

$item_key_atomic_types = array_merge($item_key_atomic_types, array_values($key_type->getTypes()));
$item_key_atomic_types = array_merge(
$item_key_atomic_types,
array_values($key_type->getAtomicTypes())
);

if ($key_type->isSingleStringLiteral()) {
$item_key_literal_type = $key_type->getSingleStringLiteral();
@@ -246,7 +249,7 @@ public static function analyze(

$item_value_atomic_types = array_merge(
$item_value_atomic_types,
array_values($item_value_type->getTypes())
array_values($item_value_type->getAtomicTypes())
);
} else {
$item_value_atomic_types[] = new Type\Atomic\TMixed();
@@ -919,7 +919,7 @@ private static function scrapeEqualityAssertions(
$type = $source->node_data->getType($whichclass_expr);

if ($type && $var_name) {
foreach ($type->getTypes() as $type_part) {
foreach ($type->getAtomicTypes() as $type_part) {
if ($type_part instanceof Type\Atomic\TTemplateParamClass) {
$if_types[$var_name] = [['=' . $type_part->param_name]];
}
@@ -1497,7 +1497,7 @@ private static function scrapeInequalityAssertions(
$type = $source->node_data->getType($whichclass_expr);

if ($type && $var_name) {
foreach ($type->getTypes() as $type_part) {
foreach ($type->getAtomicTypes() as $type_part) {
if ($type_part instanceof Type\Atomic\TTemplateParamClass) {
$if_types[$var_name] = [['!=' . $type_part->param_name]];
}
@@ -1815,7 +1815,7 @@ public static function processFunctionCall(
if ($first_var_name
&& ($second_arg_type = $source->node_data->getType($expr->args[1]->value))
) {
foreach ($second_arg_type->getTypes() as $atomic_type) {
foreach ($second_arg_type->getAtomicTypes() as $atomic_type) {
if ($atomic_type instanceof Type\Atomic\TArray
|| $atomic_type instanceof Type\Atomic\ObjectLike
) {
@@ -1830,7 +1830,7 @@ public static function processFunctionCall(
);

if ($array_literal_types
&& count($atomic_type->type_params[1]->getTypes())
&& count($atomic_type->type_params[1]->getAtomicTypes())
) {
$literal_assertions = [];

@@ -2055,7 +2055,7 @@ protected static function getInstanceOfTypes(
if ($stmt_class_type) {
$literal_class_strings = [];

foreach ($stmt_class_type->getTypes() as $atomic_type) {
foreach ($stmt_class_type->getAtomicTypes() as $atomic_type) {
if ($atomic_type instanceof Type\Atomic\TLiteralClassString) {
$literal_class_strings[] = $atomic_type->value;
} elseif ($atomic_type instanceof Type\Atomic\TTemplateParamClass) {
@@ -2219,7 +2219,7 @@ protected static function hasGetClassCheck(
$left_class_string_t = false;

if ($left_type && $left_type->isSingle()) {
foreach ($left_type->getTypes() as $type_part) {
foreach ($left_type->getAtomicTypes() as $type_part) {
if ($type_part instanceof Type\Atomic\TClassString) {
$left_class_string_t = true;
}
@@ -2250,7 +2250,7 @@ protected static function hasGetClassCheck(
$right_class_string_t = false;

if ($right_type && $right_type->isSingle()) {
foreach ($right_type->getTypes() as $type_part) {
foreach ($right_type->getAtomicTypes() as $type_part) {
if ($type_part instanceof Type\Atomic\TClassString) {
$right_class_string_t = true;
}
@@ -2392,7 +2392,7 @@ protected static function hasTypedValueComparison(
|| $conditional->left instanceof PhpParser\Node\Expr\Variable
|| $conditional->left instanceof PhpParser\Node\Expr\PropertyFetch
|| $conditional->left instanceof PhpParser\Node\Expr\StaticPropertyFetch)
&& count($right_type->getTypes()) === 1
&& count($right_type->getAtomicTypes()) === 1
&& !$right_type->hasMixed()
) {
return self::ASSIGNMENT_TO_RIGHT;
@@ -2402,7 +2402,7 @@ protected static function hasTypedValueComparison(
&& !$conditional->left instanceof PhpParser\Node\Expr\Variable
&& !$conditional->left instanceof PhpParser\Node\Expr\PropertyFetch
&& !$conditional->left instanceof PhpParser\Node\Expr\StaticPropertyFetch
&& count($left_type->getTypes()) === 1
&& count($left_type->getAtomicTypes()) === 1
&& !$left_type->hasMixed()
) {
return self::ASSIGNMENT_TO_LEFT;
@@ -382,7 +382,7 @@ public static function updateArrayType(
$has_matching_objectlike_property = false;
$has_matching_string = false;

foreach ($child_stmt_type->getTypes() as $type) {
foreach ($child_stmt_type->getAtomicTypes() as $type) {
if ($type instanceof ObjectLike) {
if (isset($type->properties[$key_value])) {
$has_matching_objectlike_property = true;
@@ -489,7 +489,7 @@ public static function updateArrayType(
if ($key_value !== null) {
$has_matching_objectlike_property = false;

foreach ($root_type->getTypes() as $type) {
foreach ($root_type->getAtomicTypes() as $type) {
if ($type instanceof ObjectLike) {
if (isset($type->properties[$key_value])) {
$has_matching_objectlike_property = true;
@@ -555,11 +555,11 @@ public static function updateArrayType(
* @var Type\Atomic\TClassStringMap
* @psalm-suppress PossiblyUndefinedStringArrayOffset
*/
$class_string_map = $parent_type->getTypes()['array'];
$class_string_map = $parent_type->getAtomicTypes()['array'];
/**
* @var Type\Atomic\TTemplateParamClass
*/
$offset_type_part = \array_values($current_dim_type->getTypes())[0];
$offset_type_part = \array_values($current_dim_type->getAtomicTypes())[0];

$template_result = new \Psalm\Internal\Type\TemplateResult(
[],
@@ -611,7 +611,7 @@ public static function updateArrayType(
$new_child_type = null;

if (!$current_dim && !$context->inside_loop) {
$atomic_root_types = $root_type->getTypes();
$atomic_root_types = $root_type->getAtomicTypes();

if (isset($atomic_root_types['array'])) {
if ($array_atomic_type instanceof Type\Atomic\TClassStringMap) {
@@ -663,7 +663,7 @@ public static function updateArrayType(
}

if ($from_countable_object_like) {
$atomic_root_types = $new_child_type->getTypes();
$atomic_root_types = $new_child_type->getAtomicTypes();

if (isset($atomic_root_types['array'])
&& ($atomic_root_types['array'] instanceof TNonEmptyArray
@@ -222,14 +222,14 @@ public static function analyzeInstance(

$has_valid_assignment_type = false;

foreach ($lhs_type->getTypes() as $lhs_type_part) {
foreach ($lhs_type->getAtomicTypes() as $lhs_type_part) {
if ($lhs_type_part instanceof TNull) {
continue;
}

if ($lhs_type_part instanceof Type\Atomic\TFalse
&& $lhs_type->ignore_falsable_issues
&& count($lhs_type->getTypes()) > 1
&& count($lhs_type->getAtomicTypes()) > 1
) {
continue;
}

0 comments on commit 9fa2db1

Please sign in to comment.
You can’t perform that action at this time.