Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed bug GH-15375 (Nested "yield from" skips items after a valid() or
next() call on the inner generator). (iliaal)
. Fixed bug GH-22727 (RETURN opcodes for multiline expressions use the wrong
line). (Joost Waaijer)
. Fixed bug GH-23301 (Nested "yield from" yields a value twice when the
middle generator delegates again). (Lazizbek Ergashev)

Expand Down
21 changes: 21 additions & 0 deletions Zend/tests/gh22727.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
GH-22727: Return opcodes use the return statement line for multiline expressions
--FILE--
<?php

function test(): int
{
return match (true) {
true => 'not an int',
};
}

try {
test();
} catch (Throwable $e) {
echo $e::class, ': on line ', $e->getLine(), "\n";
}

?>
--EXPECT--
TypeError: on line 5
3 changes: 3 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5687,6 +5687,7 @@ static bool zend_has_finally(void) /* {{{ */
static void zend_compile_return(zend_ast *ast) /* {{{ */
{
zend_ast *expr_ast = ast->child[0];
uint32_t return_lineno = CG(zend_lineno);
bool is_generator = (CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) != 0;
bool by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;

Expand All @@ -5708,6 +5709,8 @@ static void zend_compile_return(zend_ast *ast) /* {{{ */
zend_compile_expr(&expr_node, expr_ast);
}

CG(zend_lineno) = return_lineno;

if ((CG(active_op_array)->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)
&& (expr_node.op_type == IS_CV || (by_ref && expr_node.op_type == IS_VAR))
&& zend_has_finally()) {
Expand Down
Loading