Skip to content

Commit 2ca1355

Browse files
committed
Fix assertion handling
Fix acquiring callable to assert() in namespace, and also add support for (...) to the AST printer.
1 parent 8dbd598 commit 2ca1355

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Acquire callable to assert()
3+
--FILE--
4+
<?php
5+
6+
namespace Foo;
7+
8+
$assert = assert(...);
9+
$assert(1 == 1.0, "Message 1");
10+
try {
11+
$assert(1 == 2.0, "Message 2");
12+
} catch (\AssertionError $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
16+
try {
17+
assert(false && strlen(...));
18+
} catch (\AssertionError $e) {
19+
echo $e->getMessage(), "\n";
20+
}
21+
22+
?>
23+
--EXPECT--
24+
Message 2
25+
assert(false && strlen(...))

Zend/zend_ast.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,9 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
19631963
zend_ast_export_ex(str, ast->child[1], 0, indent);
19641964
smart_str_appendc(str, ')');
19651965
break;
1966+
case ZEND_AST_CALLABLE_CONVERT:
1967+
smart_str_appends(str, "...");
1968+
break;
19661969
case ZEND_AST_CLASS_CONST:
19671970
zend_ast_export_ns_name(str, ast->child[0], 0, indent);
19681971
smart_str_appends(str, "::");

Zend/zend_compile.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4422,6 +4422,7 @@ void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
44224422
{
44234423
zend_ast *name_ast = ast->child[0];
44244424
zend_ast *args_ast = ast->child[1];
4425+
bool is_callable_convert = args_ast->kind == ZEND_AST_CALLABLE_CONVERT;
44254426

44264427
znode name_node;
44274428

@@ -4434,7 +4435,8 @@ void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
44344435
{
44354436
bool runtime_resolution = zend_compile_function_name(&name_node, name_ast);
44364437
if (runtime_resolution) {
4437-
if (zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "assert")) {
4438+
if (zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "assert")
4439+
&& !is_callable_convert) {
44384440
zend_compile_assert(result, zend_ast_get_list(args_ast), Z_STR(name_node.u.constant), NULL);
44394441
} else {
44404442
zend_compile_ns_call(result, &name_node, args_ast);
@@ -4453,8 +4455,7 @@ void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
44534455
fbc = zend_hash_find_ptr(CG(function_table), lcname);
44544456

44554457
/* Special assert() handling should apply independently of compiler flags. */
4456-
if ((args_ast->kind != ZEND_AST_CALLABLE_CONVERT) &&
4457-
fbc && zend_string_equals_literal(lcname, "assert")) {
4458+
if (fbc && zend_string_equals_literal(lcname, "assert") && !is_callable_convert) {
44584459
zend_compile_assert(result, zend_ast_get_list(args_ast), lcname, fbc);
44594460
zend_string_release(lcname);
44604461
zval_ptr_dtor(&name_node.u.constant);
@@ -4471,7 +4472,7 @@ void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
44714472
return;
44724473
}
44734474

4474-
if ((args_ast->kind != ZEND_AST_CALLABLE_CONVERT) &&
4475+
if (!is_callable_convert &&
44754476
zend_try_compile_special_func(result, lcname,
44764477
zend_ast_get_list(args_ast), fbc, type) == SUCCESS
44774478
) {

0 commit comments

Comments
 (0)