forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-14368.php
More file actions
54 lines (46 loc) · 1.08 KB
/
bug-14368.php
File metadata and controls
54 lines (46 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php // lint >= 8.0
namespace Bug14368;
final class Snowflake
{
public function __construct(
private readonly int $value,
) {}
public static function cast(int $snowflake): self
{
return new self($snowflake);
}
public function equals(?self $other): bool
{
return $this->value === $other?->value;
}
}
final class BalanceId
{
public static function work(): Snowflake
{
/** @var Snowflake */
static $work = Snowflake::cast(1);
return $work;
}
public static function holiday(): Snowflake
{
/** @var Snowflake */
static $holiday = Snowflake::cast(2);
return $holiday;
}
}
function test(Snowflake $balanceId): void
{
// First match — no error expected
$a = match (true) {
$balanceId->equals(BalanceId::work()) => -1.0,
$balanceId->equals(BalanceId::holiday()) => 1.0,
default => throw new \InvalidArgumentException(),
};
// Second match — should not report match.alwaysTrue
$b = match (true) {
$balanceId->equals(BalanceId::work()) => -2.0,
$balanceId->equals(BalanceId::holiday()) => 2.0,
default => throw new \InvalidArgumentException(),
};
}