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 696de6f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 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/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Arrays/data/bug-7954.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7993.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-7141.php');

require_once __DIR__ . '/../Rules/Functions/data/bug-7823.php';
yield from $this->gatherAssertTypes(__DIR__ . '/../Rules/Functions/data/bug-7823.php');
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ public function testBug7562(): void
{
$this->analyse([__DIR__ . '/data/bug-7562.php'], []);
}

public function testBug7823(): void
{
$this->analyse([__DIR__ . '/data/bug-7823.php'], [
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 696de6f

Please sign in to comment.