Skip to content

Commit

Permalink
Merge pull request #10207 from boesing/bugfix/issue-10203
Browse files Browse the repository at this point in the history
Allow object assertions for `mixed` values
  • Loading branch information
orklah authored Sep 28, 2023
2 parents d7236ef + 3e100b1 commit a843c30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit a843c30

Please sign in to comment.