jdaugherty commented on PR #16463:
URL: https://github.com/apache/grails-core/pull/16463#issuecomment-5939361082

   @sbglasius good catch - that was a real regression. Fixed in 
https://github.com/apache/grails-core/pull/16463/commits/9ebd139cab0e692cdef4c9923634665e002c7a34
 by applying the snapshot/merge model `visitIfElse` already had to every 
control-flow construct, rather than the blunt "non-constant for the rest of the 
method" option, so the dynamic-restriction idioms keep working inside loops and 
switches:
   
   - **`switch`**: every case starts from the pre-switch state merged with the 
previous case's fall-through state (none when that case ends in 
`break`/`return`/`throw`/`continue`); the state after the statement is merged 
from the normal exit and every `break`.
   - **`try`/`catch`/`finally`**: a `catch` starts from the merge of every 
state the `try` block passed through, since an exception can leave it after any 
statement - so a data assignment that is overwritten later in the same block 
still reaches the handler. The `finally` block is checked against every path 
into it, but only the paths that complete the `try` or a `catch` normally 
continue past the statement.
   - **Loops and closure bodies**: re-walked silently from the merged loop-head 
state until it stops changing, then walked once more with reporting on, so the 
use-before-write loop case is caught and each finding is reported exactly once. 
`break`, `continue` and a closure `return` carry their state to where they 
jump, including labelled jumps.
   
   A side effect of modelling jumps: a branch that `return`s after flattening a 
query no longer poisons the state after the `if` (previously a false positive), 
and a `case` that `break`s no longer leaks its state into the next case.
   
   Your spec is in verbatim (the `if/else` row as the control), extended with 
`do`/`while`, loop `break`/`continue`, closures, and a `try` block that 
overwrites the data assignment before the `catch`, plus dedicated cases for the 
use-before-write loop, `continue`, labelled `break`, fall-through and 
`finally`, and no-warning counterparts for constant text appended in a loop, 
chosen in every `switch` case, or assigned in both `try` and `catch`. Against 
dd71f8e the `try/catch`, `switch`, loop, `continue`, labelled-break and 
`finally` cases fail as you predicted, and so do the two "returns before the 
query" no-warning cases. Docs and the class Javadoc's limitations list are 
updated accordingly.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to