Skip to content

Commit 28da435

Browse files
ondrejmirtesclaude
andcommitted
Type ExpressionResultStorage's fallback and declare duplicate()'s return type
The native storage declared $fallback untyped instead of the twin's `?self` and registered duplicate() by hand without its return type. The property is declared as the twin's now and duplicate() registers by its generated signature. Its id-keyed result arrays deliberately replace the twin's SplObjectStorage; signature-parity.php learns to list such single differences ($deliberateDrift) with the reason, and fails once one no longer occurs. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
1 parent 6d18dba commit 28da435

2 files changed

Lines changed: 32 additions & 4 deletions

File tree

‎turbo-ext/src/ExpressionResultStorage.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,19 @@ void pt_register_expression_result_storage()
110110
reg::Class cls("PHPStan\\Analyser\\ExpressionResultStorage");
111111
ptdecl::ExpressionResultStorage::declareClass(cls);
112112
/* exprsById/resultsById/fallback must stay in this order (OBJ_PROP_NUM
113-
* slots) */
113+
* slots): the two id-keyed arrays deliberately replace the twin's
114+
* SplObjectStorage $exprResults; $fallback is the twin's `?self` */
114115
cls.privateArrayProperty("exprsById");
115116
cls.privateArrayProperty("resultsById");
116-
cls.privateNullProperty("fallback");
117+
cls.property("fallback", ZEND_ACC_PRIVATE, reg::PropertyKind::TypedNull, MAY_BE_NULL, "self");
117118

118119
/* the twin's constructor only initialized its SplObjectStorage; the
119120
* native property defaults already cover that */
120121
cls.method(sigs::__construct, [](INTERNAL_FUNCTION_PARAMETERS) {
121122
ZEND_PARSE_PARAMETERS_NONE();
122123
});
123124

124-
cls.method("duplicate", reg::Public, 0, {}, [](INTERNAL_FUNCTION_PARAMETERS) {
125+
cls.method(sigs::duplicate, [](INTERNAL_FUNCTION_PARAMETERS) {
125126
ZEND_PARSE_PARAMETERS_NONE();
126127
zv::Val result = ExpressionResultStorage(ZEND_THIS).duplicate();
127128
if (UNEXPECTED(result.isUndef())) RETURN_THROWS();

‎turbo-ext/tests/signature-parity.php‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,19 @@
3535
*/
3636
$knownDrift = [
3737
'PhpParser\\NodeTraverser' => 'pending',
38-
'PHPStan\\Analyser\\ExpressionResultStorage' => 'pending',
38+
];
39+
40+
/**
41+
* Single differences a native class keeps on purpose — class => [pattern
42+
* matched against the problem text => reason]. A pattern that matches no
43+
* problem any more is reported as stale.
44+
*
45+
* @var array<string, array<string, string>>
46+
*/
47+
$deliberateDrift = [
48+
'PHPStan\\Analyser\\ExpressionResultStorage' => [
49+
'~^property (exprResults is not declared natively|(exprsById|resultsById) is declared natively but not in PHP)$~' => 'the result table is two id-keyed arrays instead of the twin\'s SplObjectStorage',
50+
],
3951
];
4052

4153
/**
@@ -318,6 +330,21 @@ function compareMembers(string $kind, string $className, array $native, array $t
318330
);
319331
$compared += count($twin['methods']) + count($twin['properties']) + count($twin['constants']);
320332

333+
foreach ($deliberateDrift[$twinClass] ?? [] as $pattern => $reason) {
334+
$matched = false;
335+
foreach ($problems as $i => $problem) {
336+
if (preg_match($pattern, $problem) === 1) {
337+
printf("~ %s: %s (deliberate: %s)\n", $twinClass, $problem, $reason);
338+
unset($problems[$i]);
339+
$matched = true;
340+
}
341+
}
342+
if (!$matched) {
343+
$problems[] = sprintf('the deliberate difference %s matches nothing any more — remove it from $deliberateDrift', $pattern);
344+
}
345+
}
346+
$problems = array_values($problems);
347+
321348
if (isset($knownDrift[$twinClass])) {
322349
if ($problems === []) {
323350
$staleDrift[] = $twinClass;

0 commit comments

Comments
 (0)