Skip to content

Commit

Permalink
cover object type
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and clxmstaab committed Sep 20, 2022
1 parent c2c29de commit a500f22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,10 @@ static function (Type $type, callable $traverse): Type {
new AccessoryLiteralStringType(),
);
} elseif ((new ObjectWithoutClassType())->isSuperTypeOf($type)->yes()) {
return new ClassStringType();
return TypeCombinator::intersect(
new ClassStringType(),
new AccessoryLiteralStringType(),
);
}

return new ErrorType();
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/bug-5843.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Foo

function doFoo(object $object): void
{
assertType('class-string', $object::class);
assertType('class-string&literal-string', $object::class);
switch ($object::class) {
case \DateTime::class:
assertType(\DateTime::class, $object);
Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-7823.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ function z($t): void
sayHello($t::class);
}

/**
* @param object $o
*/
function a($o): void
{
assertType('class-string&literal-string', $o::class);
sayHello($o::class);
}

0 comments on commit a500f22

Please sign in to comment.