Skip to content

Commit 8fd0956

Browse files
committed
Factor out common check for short-circuited ast
1 parent d568337 commit 8fd0956

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Zend/zend_compile.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,6 +2312,13 @@ static bool zend_ast_is_short_circuited(const zend_ast *ast)
23122312
}
23132313
}
23142314

2315+
static void zend_assert_not_short_circuited(const zend_ast *ast)
2316+
{
2317+
if (zend_ast_is_short_circuited(ast)) {
2318+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot take reference of a nullsafe chain");
2319+
}
2320+
}
2321+
23152322
/* Mark nodes that are an inner part of a short-circuiting chain.
23162323
* We should not perform a "commit" on them, as it will be performed by the outer-most node.
23172324
* We do this to avoid passing down an argument in various compile functions. */
@@ -3304,9 +3311,8 @@ static void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
33043311
if (!zend_is_variable_or_call(expr_ast)) {
33053312
zend_error_noreturn(E_COMPILE_ERROR,
33063313
"Cannot assign reference to non referenceable value");
3307-
} else if (zend_ast_is_short_circuited(expr_ast)) {
3308-
zend_error_noreturn(E_COMPILE_ERROR,
3309-
"Cannot take reference of a nullsafe chain");
3314+
} else {
3315+
zend_assert_not_short_circuited(expr_ast);
33103316
}
33113317

33123318
zend_compile_var(&expr_node, expr_ast, BP_VAR_W, 1);
@@ -3348,9 +3354,7 @@ static void zend_compile_assign_ref(znode *result, zend_ast *ast) /* {{{ */
33483354
zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
33493355
}
33503356
zend_ensure_writable_variable(target_ast);
3351-
if (zend_ast_is_short_circuited(source_ast)) {
3352-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot take reference of a nullsafe chain");
3353-
}
3357+
zend_assert_not_short_circuited(source_ast);
33543358
if (is_globals_fetch(source_ast)) {
33553359
zend_error_noreturn(E_COMPILE_ERROR, "Cannot acquire reference to $GLOBALS");
33563360
}
@@ -5026,10 +5030,7 @@ static void zend_compile_return(zend_ast *ast) /* {{{ */
50265030
expr_node.op_type = IS_CONST;
50275031
ZVAL_NULL(&expr_node.u.constant);
50285032
} else if (by_ref && zend_is_variable(expr_ast)) {
5029-
if (zend_ast_is_short_circuited(expr_ast)) {
5030-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot take reference of a nullsafe chain");
5031-
}
5032-
5033+
zend_assert_not_short_circuited(expr_ast);
50335034
zend_compile_var(&expr_node, expr_ast, BP_VAR_W, 1);
50345035
} else {
50355036
zend_compile_expr(&expr_node, expr_ast);
@@ -9329,10 +9330,7 @@ static void zend_compile_yield(znode *result, zend_ast *ast) /* {{{ */
93299330

93309331
if (value_ast) {
93319332
if (returns_by_ref && zend_is_variable(value_ast)) {
9332-
if (zend_ast_is_short_circuited(value_ast)) {
9333-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot take reference of a nullsafe chain");
9334-
}
9335-
9333+
zend_assert_not_short_circuited(value_ast);
93369334
zend_compile_var(&value_node, value_ast, BP_VAR_W, 1);
93379335
} else {
93389336
zend_compile_expr(&value_node, value_ast);

0 commit comments

Comments
 (0)