<div dir="ltr"><div dir="ltr">On Mon, Oct 21, 2024 at 10:01 AM Maurizio Cimadamore <<a href="mailto:maurizio.cimadamore@oracle.com">maurizio.cimadamore@oracle.com</a>> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>

  
  <div>
    <div>
      <p style="margin:0px 0px 1.2em">On 21/10/2024 15:39,
        Archie Cobbs wrote:</p>
      <p style="margin:0px 0px 1.2em"></p>
      <div>
        <p></p>
        <blockquote type="cite">
          <div dir="ltr">
            <div class="gmail_quote"><div>So no special treatment of loop induction variables
                is needed.<br>
              </div>
            </div>
          </div>
        </blockquote>
        <p></p>
      </div>
      <p style="margin:0px 0px 1.2em"></p>
      <p style="margin:0px 0px 1.2em">I’m not sure of that.
        I mean, I “can see” why you’d think that. But in which scope
        does STEP belong? Yes, it belongs to the for loop header - but
        it is executed <i>after</i> the loop. And, in fact, it can
        even refer to variables that would otherwise be DU outside the
        loop body:</p>
      <pre style="font-family:Consolas,Inconsolata,Courier,monospace;font-size:1em;line-height:1.2em;margin:1.2em 0px"><code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;background-color:rgb(248,248,248);white-space:pre-wrap;overflow:auto;border-radius:3px;border:1px solid rgb(204,204,204);padding:0.5em 0.7em;display:block">void m() {
   int i;
   for (int j = 0 ; j < 10 ; j = j + i) {
      i = 1; // if this is commented out, error!
   }
}
</code></pre>
      <p style="margin:0px 0px 1.2em">So I’m not sure it is
        a <i>strict</i> generalization :-)</p></div></div></blockquote><div>Sorry for not being more precise... all that I am implying by "generalization" is this:</div><div><ul><li>Let X be a program X that currently does not compile, but would successfully compile under the proposal in JDK-8341785 (allow capture of basic for() loop variables)<br></li><li>Then X would also compile under the <span class="gmail-im">"final or effectively frozen at
                the point of capture" proposal<br></span></li></ul></div></div><div>Proof: Let v be the variable. It must be the case that v is not modified in the body of the for() loop. It must also be the case that v is not modified after the for() loop, because v is declared in the for()  loop INIT section. It must also be the case that the lambda is contained in the body of the for() loop. Therefore, it is not possible for v to be modified at any point in the source code of the program that lexically follows the lambda. Therefore v is <span class="gmail-im">final or effectively frozen at
                the point of capture" with respect to that lambda.</span></div><div><span class="gmail-im"><br></span></div><div><span class="gmail-im">-AC<br></span></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>