Skip to content

Commit

Permalink
Fix bug where return type checking was overzealous and interfered wit…
Browse files Browse the repository at this point in the history
…h generators
  • Loading branch information
ircmaxell committed Feb 18, 2015
1 parent 9109e48 commit e2053fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Zend/tests/generators/generator_return_without_value.phpt
Original file line number Diff line number Diff line change
@@ -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) {
}
3 changes: 2 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e2053fa

Please sign in to comment.