-
-
Save nielsdos/50dc71718639c3af05db84a4dea6eb71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c | |
index f3f6d1b75ae..feed3aec2d5 100644 | |
--- a/Zend/zend_compile.c | |
+++ b/Zend/zend_compile.c | |
@@ -4335,6 +4335,11 @@ static zend_result zend_compile_func_cuf(znode *result, zend_ast_list *args, zen | |
} | |
/* }}} */ | |
+static zend_ast *zend_create_assert_arg_ast(zend_ast *operand) | |
+{ | |
+ return zend_ast_create_zval_from_str(zend_ast_export("assert(", operand, ")"));; | |
+} | |
+ | |
static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string *name, zend_function *fbc, uint32_t lineno) /* {{{ */ | |
{ | |
if (EG(assertions) >= 0) { | |
@@ -4358,8 +4363,7 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string | |
if (args->children == 1) { | |
/* add "assert(condition) as assertion message */ | |
- zend_ast *arg = zend_ast_create_zval_from_str( | |
- zend_ast_export("assert(", args->child[0], ")")); | |
+ zend_ast *arg = zend_create_assert_arg_ast(args->child[0]); | |
if (args->child[0]->kind == ZEND_AST_NAMED_ARG) { | |
/* If the original argument was named, add the new argument as named as well, | |
* as mixing named and positional is not allowed. */ | |
@@ -6454,6 +6458,16 @@ static void zend_compile_pipe(znode *result, zend_ast *ast) | |
/* Turn $foo |> bar(...) into bar($foo). */ | |
if (callable_ast->kind == ZEND_AST_CALL | |
&& callable_ast->child[1]->kind == ZEND_AST_CALLABLE_CONVERT) { | |
+ /* Add assertion message here already because we lose the original AST upon rewriting, | |
+ * causing an assertion failure in assert compilation. */ | |
+ // TODO: runtime evaluation bool??? | |
+ zend_ast *name_ast = callable_ast->child[0]; | |
+ if (name_ast->kind == ZEND_AST_ZVAL | |
+ && Z_TYPE_P(zend_ast_get_zval(name_ast)) == IS_STRING | |
+ && zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "assert")) { | |
+ zend_ast_list_add(arg_list_ast, zend_create_assert_arg_ast(operand_ast)); | |
+ } | |
+ | |
fcall_ast = zend_ast_create(ZEND_AST_CALL, | |
callable_ast->child[0], arg_list_ast); | |
/* Turn $foo |> bar::baz(...) into bar::baz($foo). */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment