Skip to content

Commit 7af8b74

Browse files
ondrejmirtesclaude
andcommitted
Hold the parenthesized arrow functions the native parser tracks
The set of parenthesized arrow functions was keyed by object handle without keeping the node alive, while php-parser's SplObjectStorage holds it. Error recovery can drop a parenthesized ArrowFunction; a later unparenthesized one reusing its handle then passed for parenthesized and "Arrow functions on the right hand side of |> must be parenthesized" was lost. Store an owned copy with a ZVAL_PTR_DTOR destructor, like the createdArrays tracker does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Fdg8n3eEi4ZoXa4dA2k4A
1 parent 809098d commit 7af8b74

5 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎turbo-ext/src/parser/ParserEngine.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class ParserEngine
211211

212212
/* per-parse trackers (native equivalents of the SplObjectStorages) */
213213
HashTable createdArrays; /* obj handle => zval of Array_ node (owned) */
214-
HashTable parenthesizedArrowFns; /* obj handle => null */
214+
HashTable parenthesizedArrowFns; /* obj handle => zval of ArrowFunction node (owned) */
215215

216216
/* ===== the LALR loop (ParserRunner.cpp) ===== */
217217

‎turbo-ext/src/parser/ParserRunner.cpp‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ParserEngine::ParserEngine(zval *parserObj, zval *errorHandler)
6969
tables = &g_tables;
7070
semValue = zv::Val::null();
7171
zend_hash_init(&createdArrays, 8, NULL, ZVAL_PTR_DTOR, 0);
72-
zend_hash_init(&parenthesizedArrowFns, 8, NULL, NULL, 0);
72+
zend_hash_init(&parenthesizedArrowFns, 8, NULL, ZVAL_PTR_DTOR, 0);
7373
}
7474

7575
ParserEngine::~ParserEngine()
@@ -483,11 +483,14 @@ void ParserEngine::createdArraysRemove(zv::Ref arrayNode)
483483
zend_hash_index_del(&createdArrays, Z_OBJ_HANDLE_P(arrayNode.raw()));
484484
}
485485

486+
/* keeps the node alive like the twin's SplObjectStorage: error recovery can
487+
* drop a parenthesized arrow function, and a later one reusing its handle
488+
* must not pass for parenthesized */
486489
void ParserEngine::parenthesizedArrowFunctionsAdd(zv::Ref expr)
487490
{
488-
zval null;
489-
ZVAL_NULL(&null);
490-
zend_hash_index_update(&parenthesizedArrowFns, Z_OBJ_HANDLE_P(expr.raw()), &null);
491+
zval copy;
492+
ZVAL_COPY(&copy, expr.raw());
493+
zend_hash_index_update(&parenthesizedArrowFns, Z_OBJ_HANDLE_P(expr.raw()), &copy);
491494
}
492495

493496
/* }}} */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
// error recovery frees a parenthesized arrow function; the next one can reuse
3+
// its object handle and must still get the |> parenthesization error
4+
if ((fn($x) => $x) { } $b = 1 |> fn($x) => $x;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
// error recovery frees a parenthesized arrow function; the next one can reuse
3+
// its object handle and must still get the |> parenthesization error
4+
f((fn() => 1) 2); 1 |> fn() => 1;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
// error recovery frees a parenthesized arrow function; the next one can reuse
3+
// its object handle and must still get the |> parenthesization error
4+
$a = (fn($q) => $q) +;
5+
$y |> fn() => 1;

0 commit comments

Comments
 (0)