From ccc06e252bdf4c54cb2c96dbcab9a2aeb933181c Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 12 Feb 2016 17:55:29 +0100 Subject: [PATCH] Forbid yield from in by-reference generators The current yield from implementation doesn't support by-ref yields. It's likely not worthwhile to actually implement this, but we should at least keep the door open for the future by issuing a compile error. Refs bug #71252. --- Zend/tests/generators/yield_from_by_reference.phpt | 12 ++++++++++++ Zend/zend_compile.c | 5 +++++ 2 files changed, 17 insertions(+) create mode 100644 Zend/tests/generators/yield_from_by_reference.phpt diff --git a/Zend/tests/generators/yield_from_by_reference.phpt b/Zend/tests/generators/yield_from_by_reference.phpt new file mode 100644 index 0000000000..8412a32af5 --- /dev/null +++ b/Zend/tests/generators/yield_from_by_reference.phpt @@ -0,0 +1,12 @@ +--TEST-- +Yield from by reference is not supported +--FILE-- + +--EXPECTF-- +Fatal error: Cannot use "yield from" inside a by-reference generator in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 58be2ed2e8..56da2962bd 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6294,6 +6294,11 @@ void zend_compile_yield_from(znode *result, zend_ast *ast) /* {{{ */ zend_mark_function_as_generator(); + if (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) { + zend_error_noreturn(E_COMPILE_ERROR, + "Cannot use \"yield from\" inside a by-reference generator"); + } + zend_compile_expr(&expr_node, expr_ast); zend_emit_op_tmp(result, ZEND_YIELD_FROM, &expr_node, NULL); } -- 2.40.0