-
Couldn't load subscription status.
- Fork 45
suggest new catch/finally parents #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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...
No description provided.