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

Allow object assertions for mixed values #10207

Merged
merged 1 commit into from
Sep 28, 2023
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: 1 addition & 1 deletion src/Psalm/Internal/Type/SimpleAssertionReconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ private static function reconcileObject(
bool $is_equality
): Union {
if ($existing_var_type->hasMixed()) {
return Type::getObject();
return new Union([$assertion_type]);
}

$old_var_type_string = $existing_var_type->getId();
Expand Down
16 changes: 16 additions & 0 deletions tests/AssertAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2967,6 +2967,22 @@ final class Qoo extends AbstractSingleInstancePluginManager
'ignored_issues' => [],
'php_version' => '8.1',
],
'objectShapeAssertion' => [
'code' => '<?php
/** @psalm-assert object{foo:string,bar:int} $value */
function assertObjectShape(mixed $value): void
{}

/** @var mixed $value */
$value = null;
assertObjectShape($value);
',
'assertions' => [
'$value===' => 'object{foo:string, bar:int}',
],
'ignored_issues' => [],
'php_version' => '8.0',
],
];
}

Expand Down
Loading