diff options
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | Zend/tests/bug72373.phpt | 20 | ||||
-rw-r--r-- | Zend/zend_compile.c | 3 |
3 files changed, 25 insertions, 1 deletions
@@ -2,6 +2,9 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2016, PHP 7.1.0alpha2 +- Core: + . Fixed bug #72373 (TypeError after Generator function w/declared return type + finishes). (Nikita) 09 Jun 2016, PHP 7.1.0alpha1 diff --git a/Zend/tests/bug72373.phpt b/Zend/tests/bug72373.phpt new file mode 100644 index 0000000000..67377c5ba7 --- /dev/null +++ b/Zend/tests/bug72373.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #72373: TypeError after Generator function w/declared return type finishes +--FILE-- +<?php + +function foo() : Generator { + yield 1; + yield 2; + yield 3; +} + +foreach (foo() as $bar) { + echo $bar . "\n"; +} + +?> +--EXPECT-- +1 +2 +3 diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 30d28cd842..2b935a8f4d 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2329,7 +2329,8 @@ void zend_emit_final_return(int return_one) /* {{{ */ zend_op *ret; zend_bool returns_reference = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0; - if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) { + if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE + && !(CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR)) { zend_emit_return_type_check(NULL, CG(active_op_array)->arg_info - 1, 1); } |