com php-src: Fix bug where return type checking was overzealous and interfered with generators: Zend/tests/generators/generator_r
eturn_without_value.phpt Zend/zend_compile.c

From: Date: Wed, 18 Feb 2015 15:59:33 +0000
Subject: com php-src: Fix bug where return type checking was overzealous and interfered with generators: Zend/tests/generators/generator_r
eturn_without_value.phpt Zend/zend_compile.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85698@lists.php.net to get a copy of this message
Commit: e2053fa94cb39369bfed53d237ef093ccebd8288 Author: Anthony Ferrara <ircmaxell@gmail.com> Wed, 18 Feb 2015 10:59:33 -0500 Parents: 9109e487493c7cf6b5fe732846bdd5efd20eb71b Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e2053fa94cb39369bfed53d237ef093ccebd8288 Log: Fix bug where return type checking was overzealous and interfered with generators Changed paths: A Zend/tests/generators/generator_return_without_value.phpt M Zend/zend_compile.c Diff: diff --git a/Zend/tests/generators/generator_return_without_value.phpt b/Zend/tests/generators/generator_return_without_value.phpt new file mode 100644 index 0000000..c50d591 --- /dev/null +++ b/Zend/tests/generators/generator_return_without_value.phpt @@ -0,0 +1,25 @@ +--TEST-- +Generators can return without values +--FILE-- +<?php + +function gen() { + yield; + return; +} + +function gen2() { + yield; + return null; +} + +var_dump(gen()); + +var_dump(gen2()); + +?> +--EXPECTF-- +object(Generator)#%d (0) { +} +object(Generator)#%d (0) { +} \ No newline at end of file diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 15019c2..a77c19d 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3268,7 +3268,8 @@ void zend_compile_return(zend_ast *ast) /* {{{ */ opline->op1.var = CG(context).fast_call_var; } - if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) { + // Generator return types are handled separately + if (!(CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) && CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) { zend_arg_info *arg_info = CG(active_op_array)->arg_info - 1; /* for scalar, weak return types, the value may be casted

« previous php.cvs (#85698) next »