Skip to content

Commit 7a44301

Browse files
committed
do not allow generators with type hints
moar tests
1 parent 5182ef4 commit 7a44301

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Zend/tests/return_hint/013.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class foo {
1414
$baz = new foo();
1515
var_dump($func=$baz->bar(), $func());
1616
?>
17-
--EXPECT--
18-
Fatal error: the function {closure} was expected to return array and returned null in %s on line %d
17+
--EXPECTF--
18+
Fatal error: the function %s was expected to return array and returned null in %s on line %d
1919

Zend/tests/return_hint/014.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Basic return hints no yield
3+
--FILE--
4+
<?php
5+
function foo() : array {
6+
yield;
7+
}
8+
9+
foo();
10+
?>
11+
--EXPECTF--
12+
Fatal error: The "yield" expression can not be used inside a function with a return type hint in %s on line %d
13+
14+

Zend/zend_compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,10 @@ void zend_do_yield(znode *result, znode *value, const znode *key, zend_bool is_v
28932893
if (!CG(active_op_array)->function_name) {
28942894
zend_error_noreturn(E_COMPILE_ERROR, "The \"yield\" expression can only be used inside a function");
28952895
}
2896+
2897+
if (CG(active_op_array)->return_hint.used) {
2898+
zend_error_noreturn(E_COMPILE_ERROR, "The \"yield\" expression can not be used inside a function with a return type hint");
2899+
}
28962900

28972901
CG(active_op_array)->fn_flags |= ZEND_ACC_GENERATOR;
28982902

0 commit comments

Comments
 (0)