1
0
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:
orklah 2022-01-15 23:27:33 +01:00 committed by GitHub
commit 3c726e76df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -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([

View File

@ -24,7 +24,7 @@ class GetObjectVarsTest extends TestCase
yield 'omitsPrivateAndProtectedPropertiesWhenCalledOutsideOfClassScope' => [
'<?php
class C {
final class C {
/** @var string */
private $priv = "val";