Skip to content

Commit 65d70a6

Browse files
committed
Fix parser expectation error for amp token
Currently, this is only handled for the "unexpected token" part of the message, but not the "expected" part. Fixes GH-18026
1 parent d7e2f28 commit 65d70a6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Zend/tests/gh18026.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-18026: Confusing "amp" reference in parser error
3+
--FILE--
4+
<?php
5+
6+
class Demo {
7+
private (set) mixed $v1;
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Parse error: syntax error, unexpected token ")", expecting token "&" in %s on line %d

Zend/zend_language_parser.y

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,14 @@ static YYSIZE_T zend_yytnamerr(char *yyres, const char *yystr)
18191819
return sizeof("\"\\\"")-1;
18201820
}
18211821

1822+
/* We used "amp" as a dummy label to avoid a duplicate token literal warning. */
1823+
if (strcmp(toktype, "\"amp\"") == 0) {
1824+
if (yyres) {
1825+
yystpcpy(yyres, "token \"&\"");
1826+
}
1827+
return sizeof("token \"&\"")-1;
1828+
}
1829+
18221830
/* Strip off the outer quote marks */
18231831
if (toktype_len >= 2 && *toktype == '"') {
18241832
toktype++;

0 commit comments

Comments
 (0)