Skip to content

Commit

Permalink
Merge branch refs/heads/1.10.x into 1.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
phpstan-bot committed Feb 23, 2024
2 parents f163292 + a06d509 commit 0d9e8ea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ private function resolveType(string $exprString, Expr $node): Type
if ($node->class instanceof Name) {
$staticMethodCalledOnType = $this->resolveTypeByName($node->class);
} else {
$staticMethodCalledOnType = $this->getType($node->class)->getObjectTypeOrClassStringObjectType();
$staticMethodCalledOnType = TypeCombinator::removeNull($this->getType($node->class))->getObjectTypeOrClassStringObjectType();
}

$returnType = $this->methodCallReturnType(
Expand Down Expand Up @@ -1894,7 +1894,7 @@ private function resolveType(string $exprString, Expr $node): Type
if ($node->class instanceof Name) {
$staticPropertyFetchedOnType = $this->resolveTypeByName($node->class);
} else {
$staticPropertyFetchedOnType = $this->getType($node->class)->getObjectTypeOrClassStringObjectType();
$staticPropertyFetchedOnType = TypeCombinator::removeNull($this->getType($node->class))->getObjectTypeOrClassStringObjectType();
}

$returnType = $this->propertyFetchType(
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ public function dataFileAsserts(): iterable
if (PHP_VERSION_ID >= 80000) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10071.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9394.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-nullsafe-prop-static-access.php');
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/allowed-subtypes-datetime.php');
Expand Down
28 changes: 28 additions & 0 deletions tests/PHPStan/Analyser/data/bug-nullsafe-prop-static-access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1); // lint >= 8.0

namespace BugNullsafePropStaticAccess;

class A
{
public function __construct(public readonly B $b)
{}
}

class B
{
public static int $value = 0;

public static function get(): string
{
return 'B';
}
}

function foo(?A $a): void
{
\PHPStan\Testing\assertType('string|null', $a?->b::get());
\PHPStan\Testing\assertType('string|null', $a?->b->get());

\PHPStan\Testing\assertType('int|null', $a?->b::$value);
\PHPStan\Testing\assertType('int|null', $a?->b->value);
}

0 comments on commit 0d9e8ea

Please sign in to comment.