Skip to content

Commit a70580c

Browse files
committed
Update TypeSpecifierContext.php
1 parent a6a7430 commit a70580c

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/Analyser/TypeSpecifierContext.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace PHPStan\Analyser;
44

55
use PHPStan\ShouldNotHappenException;
6-
use PHPStan\Type\MixedType;
76
use PHPStan\Type\Type;
87

98
/**
@@ -23,29 +22,37 @@ final class TypeSpecifierContext
2322
/** @var self[] */
2423
private static array $registry;
2524

26-
private function __construct(private ?int $value)
25+
private function __construct(
26+
private ?int $value,
27+
private ?Type $returnType,
28+
)
2729
{
2830
}
2931

30-
private static function create(?int $value): self
32+
private static function create(?int $value, ?Type $returnType = null): self
3133
{
32-
self::$registry[$value] ??= new self($value);
34+
if ($returnType !== null) {
35+
// return type bound context is unique for each context and therefore not cachable
36+
return new self($value, $returnType);
37+
}
38+
39+
self::$registry[$value] ??= new self($value, null);
3340
return self::$registry[$value];
3441
}
3542

36-
public static function createTrue(): self
43+
public static function createTrue(?Type $returnType = null): self
3744
{
38-
return self::create(self::CONTEXT_TRUE);
45+
return self::create(self::CONTEXT_TRUE, $returnType);
3946
}
4047

4148
public static function createTruthy(): self
4249
{
4350
return self::create(self::CONTEXT_TRUTHY);
4451
}
4552

46-
public static function createFalse(): self
53+
public static function createFalse(?Type $returnType = null): self
4754
{
48-
return self::create(self::CONTEXT_FALSE);
55+
return self::create(self::CONTEXT_FALSE, $returnType);
4956
}
5057

5158
public static function createFalsey(): self
@@ -91,9 +98,9 @@ public function null(): bool
9198
return $this->value === null;
9299
}
93100

94-
public function getReturnType(): Type
101+
public function getReturnType(): ?Type
95102
{
96-
return new MixedType();
103+
return $this->returnType;
97104
}
98105

99106
}

0 commit comments

Comments
 (0)