Skip to content

Commit 99041a3

Browse files
committed
Make sure late-resolvable types are always resolved
1 parent 63ee5de commit 99041a3

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

src/Analyser/Generator/ExprAnalysisResult.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@
55
use PHPStan\Analyser\ImpurePoint;
66
use PHPStan\Analyser\SpecifiedTypes;
77
use PHPStan\Type\Type;
8+
use PHPStan\Type\TypeUtils;
89

910
final class ExprAnalysisResult
1011
{
1112

13+
public readonly Type $type;
14+
15+
public readonly Type $nativeType;
16+
1217
public readonly Type $keepVoidType;
1318

1419
/**
1520
* @param InternalThrowPoint[] $throwPoints
1621
* @param ImpurePoint[] $impurePoints
1722
*/
1823
public function __construct(
19-
public readonly Type $type,
20-
public readonly Type $nativeType,
24+
Type $type,
25+
Type $nativeType,
2126
public readonly GeneratorScope $scope,
2227
public readonly bool $hasYield,
2328
public readonly bool $isAlwaysTerminating,
@@ -29,7 +34,14 @@ public function __construct(
2934
?Type $keepVoidType = null,
3035
)
3136
{
32-
$this->keepVoidType = $keepVoidType ?? $type;
37+
$this->type = TypeUtils::resolveLateResolvableTypes($type);
38+
$this->nativeType = TypeUtils::resolveLateResolvableTypes($nativeType);
39+
40+
if ($keepVoidType !== null) {
41+
$this->keepVoidType = TypeUtils::resolveLateResolvableTypes($keepVoidType);
42+
} else {
43+
$this->keepVoidType = $this->type;
44+
}
3345
}
3446

3547
}

src/Analyser/Generator/GeneratorScope.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,21 +2422,17 @@ public function getAnonymousFunctionReturnType(): ?Type
24222422
/** @api */
24232423
public function getType(Expr $node): Type
24242424
{
2425-
return TypeUtils::resolveLateResolvableTypes(
2426-
Fiber::suspend(
2427-
ExprAnalysisRequest::createNoopRequest($node, $this),
2428-
)->type,
2429-
);
2425+
return Fiber::suspend(
2426+
ExprAnalysisRequest::createNoopRequest($node, $this),
2427+
)->type;
24302428
}
24312429

24322430
/** @api */
24332431
public function getNativeType(Expr $expr): Type
24342432
{
2435-
return TypeUtils::resolveLateResolvableTypes(
2436-
Fiber::suspend(
2437-
ExprAnalysisRequest::createNoopRequest($expr, $this),
2438-
)->nativeType,
2439-
);
2433+
return Fiber::suspend(
2434+
ExprAnalysisRequest::createNoopRequest($expr, $this),
2435+
)->nativeType;
24402436
}
24412437

24422438
public function doNotTreatPhpDocTypesAsCertain(): Scope
@@ -2472,11 +2468,9 @@ private function promoteNativeTypes(): self
24722468

24732469
public function getKeepVoidType(Expr $node): Type
24742470
{
2475-
return TypeUtils::resolveLateResolvableTypes(
2476-
Fiber::suspend(
2477-
ExprAnalysisRequest::createNoopRequest($node, $this),
2478-
)->keepVoidType,
2479-
);
2471+
return Fiber::suspend(
2472+
ExprAnalysisRequest::createNoopRequest($node, $this),
2473+
)->keepVoidType;
24802474
}
24812475

24822476
/**

0 commit comments

Comments
 (0)