Skip to content
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
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);
}