Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Do not consider isset checks on static properties as redundant" #5670

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -802,15 +802,13 @@ public static function addContextProperties(
) {
$property_type->initialized = false;
$property_type->from_property = true;
$property_type->from_static_property = $property_storage->is_static === true;
}
} else {
$property_type = Type::getMixed();

if (!$property_storage->has_default && !$property_storage->is_promoted) {
$property_type->initialized = false;
$property_type->from_property = true;
$property_type->from_static_property = $property_storage->is_static === true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ public static function analyze(
if ($assign_value_type) {
$assign_value_type = clone $assign_value_type;
$assign_value_type->from_property = false;
$assign_value_type->from_static_property = false;
$assign_value_type->ignore_isset = false;
} else {
$assign_value_type = Type::getMixed();
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/Type/NegatedAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public static function reconcile(
&& $key
&& strpos($key, '[') === false
&& $key !== '$_SESSION'
&& !$existing_var_type->from_static_property
) {
foreach ($existing_var_type->getAtomicTypes() as $atomic) {
if (!$existing_var_type->hasMixed()
Expand Down
2 changes: 0 additions & 2 deletions src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,6 @@ private static function reconcileIsset(
&& (!$did_remove_type || empty($existing_var_type->getAtomicTypes()))
&& $key
&& $code_location
&& !$existing_var_type->from_static_property
) {
self::triggerIssueForImpossible(
$existing_var_type,
Expand All @@ -459,7 +458,6 @@ private static function reconcileIsset(
}

$existing_var_type->from_property = false;
$existing_var_type->from_static_property = false;
$existing_var_type->possibly_undefined = false;
$existing_var_type->possibly_undefined_from_try = false;
$existing_var_type->ignore_isset = false;
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/Type/TypeExpander.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public static function expandUnion(
$fleshed_out_type->by_ref = $return_type->by_ref;
$fleshed_out_type->initialized = $return_type->initialized;
$fleshed_out_type->from_property = $return_type->from_property;
$fleshed_out_type->from_static_property = $return_type->from_static_property;
$fleshed_out_type->had_template = $return_type->had_template;
$fleshed_out_type->parent_nodes = $return_type->parent_nodes;

Expand Down
10 changes: 0 additions & 10 deletions src/Psalm/Type/Union.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ class Union implements TypeNode
*/
public $from_property = false;

/**
* Whether the type originated from *static* property
*
* Unlike non-static properties, static properties have no prescribed place
* like __construct() to be initialized in
*
* @var bool
*/
public $from_static_property = false;

/**
* Whether the property that this type has been derived from has been initialized in a constructor
*
Expand Down
28 changes: 0 additions & 28 deletions tests/TypeReconciliation/IssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1006,34 +1006,6 @@ function foo(array $test) : void {
echo $test[0];
}'
],
'issetOnStaticProperty' => [
'<?php
class Singleton {
private static self $instance;
public function getInstance(): self {
if (isset(self::$instance)) {
return self::$instance;
}
return self::$instance = new self();
}
private function __construct() {}
}
',
],
'negatedIssetOnStaticProperty' => [
'<?php
class Singleton {
private static self $instance;
public function getInstance(): self {
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
private function __construct() {}
}
',
],
];
}

Expand Down