Skip to content

Commit c1a8fd5

Browse files
ondrejmirtesclaude
andcommitted
Compare integer argument keys signed when the native reorderArgs() sorts them
The native ArgumentsNormalizer::reorderArgs() sorted the reordered arguments comparing integer keys as zend_ulong, so a negative key sorted last, where the twin's ksort() puts it first. Compare them as zend_long. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
1 parent ed774ca commit c1a8fd5

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎turbo-ext/src/ArgumentsNormalizer.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,8 @@ class ArgumentsNormalizer
593593
/* the ksort() key order of two buckets */
594594
static int compareKeys(Bucket *a, Bucket *b)
595595
{
596-
if (a->key == NULL && b->key == NULL) return a->h < b->h ? -1 : (a->h > b->h ? 1 : 0);
596+
/* integer keys compare signed, like ksort() */
597+
if (a->key == NULL && b->key == NULL) return (zend_long) a->h < (zend_long) b->h ? -1 : ((zend_long) a->h > (zend_long) b->h ? 1 : 0);
597598
zval first, second;
598599
if (a->key != NULL) {
599600
ZVAL_STR(&first, a->key);

‎turbo-ext/tests/smoke.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4363,6 +4363,17 @@ public function getComments(): array
43634363
'storage storeExpressionResult(stmt, result)' => $lemOutcome(static fn () => (new $lemStorageClass())->storeExpressionResult(new \PhpParser\Node\Stmt\Nop(), $makeResult())),
43644364
'storage findExpressionResult(stdClass)' => $lemOutcome(static fn () => (new $lemStorageClass())->findExpressionResult(new \stdClass())),
43654365
'stack push(stdClass)' => $lemOutcome(static fn () => (new $lemStackClass())->push(new \stdClass())),
4366+
// ksort() orders a negative integer key first
4367+
'reorderArgs(negative key)' => $lemOutcome(static function () use ($lemNs): array {
4368+
$normalizer = $lemNs === '\\PHPStanTurbo\\' ? \PHPStanTurbo\ArgumentsNormalizer::class : \PHPStan\Analyser\ArgumentsNormalizer::class;
4369+
$args = [
4370+
-1 => new \PhpParser\Node\Arg(new \PhpParser\Node\Scalar\Int_(10)),
4371+
0 => new \PhpParser\Node\Arg(new \PhpParser\Node\Scalar\Int_(20)),
4372+
1 => new \PhpParser\Node\Arg(new \PhpParser\Node\Scalar\Int_(30), false, false, [], new \PhpParser\Node\Identifier('b')),
4373+
];
4374+
$reordered = $normalizer::reorderArgs(new \PHPStan\Reflection\TrivialParametersAcceptor(), $args);
4375+
return $reordered === null ? [] : array_map(static fn (\PhpParser\Node\Arg $arg): int => $arg->value->value, $reordered);
4376+
}),
43664377
];
43674378
}
43684379
foreach ($lemResults['php'] as $lemLabel => $lemPhp) {

0 commit comments

Comments
 (0)