Skip to content

Commit 76f7d46

Browse files
committed
PFA: Fix support for never-returning functions
The AST rewrite tried to add a return statement, so I extended the check from void to void or never.
1 parent ed19042 commit 76f7d46

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
PFA can be made from never function
3+
--FILE--
4+
<?php
5+
6+
function neverReturns($msg): never {
7+
throw new Error($msg);
8+
}
9+
10+
var_dump(neverReturns(?) instanceof Closure);
11+
12+
?>
13+
--EXPECT--
14+
bool(true)

‎Zend/zend_partial.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ static zend_ast *zp_compile_forwarding_call(
663663
call_ast = zend_ast_create(ZEND_AST_CALL, func_name_ast, args_ast);
664664
}
665665

666-
/* Void functions can not 'return $expr' */
667-
if (ZEND_TYPE_FULL_MASK(return_type) & MAY_BE_VOID) {
666+
/* Void and never functions can not 'return $expr' */
667+
if (ZEND_TYPE_FULL_MASK(return_type) & (MAY_BE_VOID|MAY_BE_NEVER)) {
668668
stmts_ast = zend_ast_list_add(stmts_ast, call_ast);
669669
} else {
670670
zend_ast *return_ast = zend_ast_create(ZEND_AST_RETURN, call_ast);

0 commit comments

Comments
 (0)