Skip to content
Permalink
Browse files

Clean up static property reconciliation

  • Loading branch information
muglug committed Dec 11, 2019
1 parent 6b56a02 commit 612f74f48189927bfa81a61b42d9324f8f6e5c0f
Showing with 39 additions and 7 deletions.
  1. +6 −7 src/Psalm/Type/Reconciler.php
  2. +33 −0 tests/TypeReconciliation/ConditionalTest.php
@@ -401,9 +401,10 @@ public static function breakUpPathIntoParts($path)
&& $chars[$i + 2] === '$'
) {
++$i;
++$i;

++$parts_offset;
$parts[$parts_offset] = '->';
$parts[$parts_offset] = '::$';
++$parts_offset;
continue 2;
}
@@ -518,6 +519,8 @@ private static function getValueForKey(
if ($has_isset) {
$new_base_type_candidate->possibly_undefined = true;
}
} elseif ($existing_key_type_part instanceof Type\Atomic\TNull) {
$new_base_type_candidate = Type::getNull();
} elseif (!$existing_key_type_part instanceof Type\Atomic\ObjectLike) {
return Type::getMixed();
} elseif ($array_key[0] === '$' || ($array_key[0] !== '\'' && !\is_numeric($array_key[0]))) {
@@ -558,9 +561,9 @@ private static function getValueForKey(
}

$base_key = $new_base_key;
} elseif ($divider === '->') {
} elseif ($divider === '->' || $divider === '::$') {
$property_name = array_shift($key_parts);
$new_base_key = $base_key . '->' . $property_name;
$new_base_key = $base_key . $divider . $property_name;

if (!isset($existing_keys[$new_base_key])) {
$new_base_type = null;
@@ -590,10 +593,6 @@ private static function getValueForKey(
true
);

$class_storage = $codebase->classlike_storage_provider->get(
(string)$declaring_property_class
);

$class_property_type = $codebase->properties->getPropertyType(
$property_id,
false,
@@ -2254,6 +2254,21 @@ public static function getArr() : array {
}
}'
],
'assertOnStaticPropertyOffset' => [
'<?php
class C {
/** @var array<string, string>|null */
private static $map = [];
public static function foo(string $id) : ?string {
if (isset(self::$map[$id])) {
return self::$map[$id];
}
return null;
}
}',
],
];
}

@@ -2601,6 +2616,24 @@ function foo($value) : void {
}',
'error_message' => 'RedundantCondition',
],
'SKIPPED-catchRedundantConditionOnBinaryOpForwards' => [
'<?php
class App {}
function test(App $app) : void {
if ($app || rand(0, 1)) {}
}',
'error_message' => 'RedundantCondition',
],
'SKIPPED-catchRedundantConditionOnBinaryOpBackwards' => [
'<?php
class App {}
function test(App $app) : void {
if (rand(0, 1) || $app) {}
}',
'error_message' => 'RedundantCondition',
],
];
}
}

0 comments on commit 612f74f

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