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

Psalm can't be sure get_object_vars will return an empty array unless object is known AND final #7401

Merged
merged 2 commits into from Jan 15, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -43,7 +43,7 @@ public static function getGetObjectVarsReturnType(

if ($object_type instanceof TObjectWithProperties) {
if ([] === $object_type->properties) {
return Type::getEmptyArray();
return Type::parseString('array<string, mixed>');
}
return new Union([
new TKeyedArray($object_type->properties)
Expand All @@ -62,7 +62,11 @@ public static function getGetObjectVarsReturnType(
}

if ([] === $class_storage->appearing_property_ids) {
return Type::getEmptyArray();
if ($class_storage->final) {
return Type::getEmptyArray();
}

return Type::parseString('array<string, mixed>');
}

$properties = [];
Expand All @@ -86,7 +90,11 @@ public static function getGetObjectVarsReturnType(
}

if ([] === $properties) {
return Type::getEmptyArray();
if ($class_storage->final) {
return Type::getEmptyArray();
}

return Type::parseString('array<string, mixed>');
}

return new Union([
Expand Down
2 changes: 1 addition & 1 deletion tests/ReturnTypeProvider/GetObjectVarsTest.php
Expand Up @@ -24,7 +24,7 @@ class C {

yield 'omitsPrivateAndProtectedPropertiesWhenCalledOutsideOfClassScope' => [
'<?php
class C {
final class C {
/** @var string */
private $priv = "val";

Expand Down