Skip to content

Fixed GH-22727: Attribute return opcodes to return statement - #23397

Open
joostwaaijer wants to merge 1 commit into
php:PHP-8.4from
joostwaaijer:feature/fix-return-expression-lineno
Open

Fixed GH-22727: Attribute return opcodes to return statement#23397
joostwaaijer wants to merge 1 commit into
php:PHP-8.4from
joostwaaijer:feature/fix-return-expression-lineno

Conversation

@joostwaaijer

Copy link
Copy Markdown

Note

This pull request description was prepared with assistance from OpenAI Codex and reviewed by the contributor.

zend_compile_return() currently leaves CG(zend_lineno) at the last line compiled inside a multiline return expression. As a result, VERIFY_RETURN_TYPE and RETURN are attributed to a match arm or ternary branch instead of the return statement. Coverage drivers then omit the actual return line and may report a different branch line as executed. This is the specific return-expression case described in GH-22727 and is part of the broader GH-18985 issue.

This patch captures the statement line before compiling the expression and restores it before emitting return-related opcodes. It deliberately avoids the broader expression compiler changes from GH-22833 that were reverted.

A PHPT regression test verifies the user-visible TypeError line. The test fails on PHP 8.4.24 with line 6 instead of line 5, and passes on the patched PHP 8.4.26-dev build.

Validation: debug NTS build with all Zend/tests (4,837 passed, 134 skipped, 1 expected failure, 0 failures); debug ZTS build with the focused regression test; and PCOV 1.0.12 verification showing the direct return match line changes from absent to hit count 1.

@joostwaaijer
joostwaaijer marked this pull request as ready for review August 21, 2026 06:35
Comment thread Zend/tests/gh22727.phpt
Comment on lines +15 to +21
} catch (TypeError $exception) {
echo $exception->getLine(), "\n";
}

?>
--EXPECT--
5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (TypeError $exception) {
echo $exception->getLine(), "\n";
}
?>
--EXPECT--
5
} catch (Throwable $e) {
echo $e::class, ': on line ', $e->getLine(), "\n";
}
?>
--EXPECT--
TypeError: on line 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants