Skip to content

Conversation

@eric-therond
Copy link
Contributor

No description provided.

Copy link
Owner

@ircmaxell ircmaxell left a comment

Choose a reason for hiding this comment

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

Looks reasonable. The only thing missing I think is discussion around ensuring finally has a link to the parent or not...

protected function parseStmt_TryCatch(Stmt\TryCatch $node)
{
$finally = new Block($this->block);
$finally = new Block();
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is still needed, isn't it? For the case where you have nested finally, it would propagate the parent's catch context:

try {
    try {
        //...
    } finally {
        return true;
    }
} finally {
    return false;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we try propagating the parent's catch context while putting the try body block as the parent of the finally block?

Actually, the problem is more serious in the case of nested try: we must have all possible nested catch contexts within a block? This means that a block must contain an array of catch contexts, not just the closest one in the flow, as it's the case today.

Copy link
Owner

Choose a reason for hiding this comment

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

That shouldn’t be a problem. Since we always propagate a finally block (whether try has one or not), and that finally block contains the catch context of the parent (with the original implementation), we can reconstruct based upon what’s in the propagated finally. So basically hit finally block, if the exception is still valid at the end, find the next in the parent catch context for the finally block (inherited from the parent).

this is preferable to merging catch blocks, as it respects finally by design.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, that's clear to me.
I've updated the PR.

$parsedTypes[] = $this->parseTypeNode($type);
}

$type = new Op\Type\Union(
Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, this is a much better approach...

@ircmaxell ircmaxell merged commit 885dfd5 into ircmaxell:TRYCATCH Aug 10, 2025
6 checks passed
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.

2 participants