Skip to content

Tweak lineno compilation#22833

Open
iluuu1994 wants to merge 1 commit into
php:masterfrom
iluuu1994:gh-18985
Open

Tweak lineno compilation#22833
iluuu1994 wants to merge 1 commit into
php:masterfrom
iluuu1994:gh-18985

Conversation

@iluuu1994

Copy link
Copy Markdown
Member

zend_compile_expr() and zend_compile_var() now restore CG(zend_lineno) after compilation of the node has finished. This makes the compiled lineno more predictable.

Fixes GH-18985

Note that there are many cases left that are incorrect. For example:

<?php

return
    foo();
L0004 0000 INIT_FCALL_BY_NAME 0 string("foo")
L0004 0001 T0 = DO_FCALL_BY_NAME
L0004 0002 RETURN T0
L0007 0003 RETURN int(1)

zend_ast_create_1() set lineno to the lineno of the first available child. In this case that's foo(), even though it's not on the same line as return. What we'd need instead is backing up CG(zend_lineno) after the return keyword in the parser so we can restore it later. However, this would be a rather invasive change, given the same issue exists for many ast kinds, so a better solution might just be to re-commit e528762.

I don't feel comfortable backporting this as a bug fix, but we might address the issue in a simpler, less comprehensive manner for older branches.

zend_compile_expr() and zend_compile_var() now restore CG(zend_lineno) after
compilation of the node has finished. This makes the compiled lineno more
predictable.

Fixes phpGH-18985
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.

Inner expression compilation (for match) can result in wrong line numbers

1 participant