Skip to content

fix(vm): try/finally execution — return defers through finally (#3082)#3106

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-3082-vm-try-finally
May 29, 2026
Merged

fix(vm): try/finally execution — return defers through finally (#3082)#3106
PurHur merged 1 commit into
masterfrom
agent/issue-3082-vm-try-finally

Conversation

@PurHur
Copy link
Copy Markdown
Owner

@PurHur PurHur commented May 29, 2026

Summary

Closes #3082.

  • Normal try/finally and try/catch/finally on throw already worked on master; added compliance PHPTs.
  • Gap fixed: return / return $v inside try now runs pending finally handlers first (including nested try), matching Zend unwind semantics.
  • Mark the handler’s finally complete when leaving the finally CFG block so end-of-script return does not re-run finally.

php-src reference

  • Zend/zend_exceptions.czend_execute_finally()
  • Zend/zend_compile.c — try/finally CFG

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/unit/TryCatchComplianceTest.php'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/compliance/VMTest.php --filter "try_finally|try_catch_finally"'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh; php bin/vm.php -r "try { echo \"t\"; return; } finally { echo \"f\"; }"'
# tf

JIT follow-up remains in #2114.

Made with Cursor

Defer TYPE_RETURN through pending-finally handlers (nested try supported),
mark finally complete when leaving the finally CFG block, and add compliance
tests for normal, catch+throw, and return paths.

php-src: Zend/zend_exceptions.c (zend_execute_finally)
Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur PurHur force-pushed the agent/issue-3082-vm-try-finally branch from 7829782 to 8326138 Compare May 29, 2026 13:31
@PurHur PurHur merged commit 742db59 into master May 29, 2026
@PurHur PurHur deleted the agent/issue-3082-vm-try-finally branch May 29, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language: VM try/finally execution — finally blocks not run (#57 follow-up)

1 participant