-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
JitBug.php
89 lines (67 loc) · 2.77 KB
/
JitBug.php
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
declare(strict_types=1);
// Linux: php -dzend_extension=opcache -dopcache.enable_cli=1 -dopcache.jit_buffer_size=100M -dopcache.jit=tracing Dev/bugs/JitBug.php
// Windows: php -d zend_extension=opcache -d opcache.enable_cli=1 -d opcache.jit_buffer_size=100M -d opcache.jit=tracing Dev/bugs/JitBug.php
# Notes
// Not happening on 8.1
// Bug only with jit tracing mode (working with jit function) (test on PHP 8.0.10 NTS on x64)
// Working with or without opcache
# Bugs
// PHP Fatal error: Uncaught TypeError: CondorcetPHP\Condorcet\Result::__construct(): Argument #6 ($seats) must be of type ?int, CondorcetPHP\Condorcet\Election given, called in C:\dev_scripts\Condorcet\lib\Algo\Method.php on line 84 and defined in C:\dev_scripts\Condorcet\lib\Result.php:89
// Stack trace:
// #0 C:\dev_scripts\Condorcet\lib\Algo\Method.php(84): CondorcetPHP\Condorcet\Result->__construct()
// #1 C:\dev_scripts\Condorcet\lib\Algo\Methods\STV\SingleTransferableVote.php(91): CondorcetPHP\Condorcet\Algo\Method->createResult()
// #2 C:\dev_scripts\Condorcet\lib\Algo\Method.php(63): CondorcetPHP\Condorcet\Algo\Methods\STV\SingleTransferableVote->compute()
// #3 C:\dev_scripts\Condorcet\lib\ElectionProcess\ResultsProcess.php(80): CondorcetPHP\Condorcet\Algo\Method->getResult()
// #4 C:\dev_scripts\Condorcet\Dev\bugs\JitBug.php(24): CondorcetPHP\Condorcet\Election->getResult()
// #5 {main}
// thrown in C:\dev_scripts\Condorcet\lib\Result.php on line 89
# Test code
namespace CondorcetPHP\Condorcet;
require_once __DIR__ . '/../../__CondorcetAutoload.php';
for ($i = 1; $i <= 4000; $i++) {
# With Condorcet
$election = new Election;
$election->parseCandidates('A;B;C');
$election->addVote('A>B>C');
$election->getResult('Schulze');
$election->getResult('STV');
# Tentative to reproduce (impossible...)
// $a = new A (new Bar);
// $b = new B (new Bar);
}
# Tentative to reproduce (impossible...)
class Foo
{
public function __construct(public string $fromMethod, public string $byClass, public Bar $election, public array $result, public $stats, public ?int $seats = null, public array $methodOptions = []) {}
}
class Bar {}
abstract class Base
{
public const IS_PROPORTIONAL = false;
public Foo $foo;
public function __construct(public Bar $barInstance)
{
$this->foo = new Foo(
fromMethod: 'test',
byClass: $this::class,
election: $this->barInstance,
result: [],
stats: [],
seats: (static::IS_PROPORTIONAL) ? $this->getSeats() : null,
methodOptions: []
);
}
public function getSeats(): int
{
return 6;
}
}
class A extends Base
{
public const IS_PROPORTIONAL = false;
}
class B extends Base
{
public const IS_PROPORTIONAL = true;
}