mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #7401 from orklah/getObjectVarsNoValue
Psalm can't be sure get_object_vars will return an empty array unless object is known AND final
This commit is contained in:
commit
3c726e76df
@ -43,7 +43,7 @@ class GetObjectVarsReturnTypeProvider implements FunctionReturnTypeProviderInter
|
||||
|
||||
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)
|
||||
@ -62,7 +62,11 @@ class GetObjectVarsReturnTypeProvider implements FunctionReturnTypeProviderInter
|
||||
}
|
||||
|
||||
if ([] === $class_storage->appearing_property_ids) {
|
||||
return Type::getEmptyArray();
|
||||
if ($class_storage->final) {
|
||||
return Type::getEmptyArray();
|
||||
}
|
||||
|
||||
return Type::parseString('array<string, mixed>');
|
||||
}
|
||||
|
||||
$properties = [];
|
||||
@ -86,7 +90,11 @@ class GetObjectVarsReturnTypeProvider implements FunctionReturnTypeProviderInter
|
||||
}
|
||||
|
||||
if ([] === $properties) {
|
||||
return Type::getEmptyArray();
|
||||
if ($class_storage->final) {
|
||||
return Type::getEmptyArray();
|
||||
}
|
||||
|
||||
return Type::parseString('array<string, mixed>');
|
||||
}
|
||||
|
||||
return new Union([
|
||||
|
@ -24,7 +24,7 @@ class GetObjectVarsTest extends TestCase
|
||||
|
||||
yield 'omitsPrivateAndProtectedPropertiesWhenCalledOutsideOfClassScope' => [
|
||||
'<?php
|
||||
class C {
|
||||
final class C {
|
||||
/** @var string */
|
||||
private $priv = "val";
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user