GROOVY-12397: VerifyError for a pattern variable bound in a later && / || operand; break and continue end an if arm
A pattern variable declared in the right operand of && or || had its slot
allocated (and null-initialised) at its instanceof site only. That operand
is skipped when the left one decides the result, so at the join a later read
of the slot (a following conjunct, the then branch) failed verification:
if (p instanceof String s && s.length() > 0 && s.trim() instanceof String t)
threw VerifyError. BinaryExpressionHelper now pre-declares the pattern
variables of the right operand before the left operand runs, and the
instanceof site reuses the pre-declared slot (CompileStack keeps the set).
VariableScopeVisitor and the if-statement writer also treated an arm ending
in break or continue as completing normally, so that
if (!(o instanceof String s)) continue
did not introduce `s` after the if as JLS §6.3.2.2-200-C / §14.22 require.
Both now use mayCompleteNormally.
5 files changed