[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-compiler-dev
Subject:    Re: RFR: JDK14-8236005: local records shouldn't capture any non-static state from any enclosing type
From:       Vicente Romero <vicente.romero () oracle ! com>
Date:       2020-01-14 12:05:18
Message-ID: adc6f43c-c04e-a133-d39d-79d6a84180a5 () oracle ! com
[Download RAW message or body]

;) sure, good catch

Vicente

On 1/14/20 5:49 AM, Maurizio Cimadamore wrote:
>
> Thanks!
>
> Maurizio
>
> On 14/01/2020 03:37, Vicente Romero wrote:
>> I will add a test in the lines of:
>>
>> class Outer<T> {
>>     void m() {
>>         record R(T t) {}
>>     }
>> }
>>
>> to the patch
>>
>> Thanks,
>> Vicente
>>
>> On 1/13/20 4:05 PM, Maurizio Cimadamore wrote:
>>>
>>> Maybe too late but we might want to add a test for type-variables - 
>>> e.g. accessing enclosing type-variables should equally be banned.
>>>
>>> Maurizio
>>>
>>> On 13/01/2020 17:46, Vicente Romero wrote:
>>>>
>>>>
>>>> On 1/13/20 9:46 AM, Maurizio Cimadamore wrote:
>>>>>
>>>>> Thanks for the explanation. I've convinced myself that the code is 
>>>>> correct. Basically, if we're trying to access a local variable 
>>>>> defined in a method whose class is != than the current class && 
>>>>> the current class is also static (which can only happen with 
>>>>> records, as that's the only local construct which can also be 
>>>>> static), an error should be issued.
>>>>>
>>>>
>>>> cool thanks,
>>>>
>>>>> Maurizio
>>>>>
>>>>
>>>> Vicente
>>>>
>>>>> On 13/01/2020 13:39, Vicente Romero wrote:
>>>>>>
>>>>>>
>>>>>> On 1/10/20 8:02 PM, Maurizio Cimadamore wrote:
>>>>>>>
>>>>>>>
>>>>>>> On 10/01/2020 22:53, Vicente Romero wrote:
>>>>>>>> but this code is accepted:
>>>>>>>>
>>>>>>>> class R {
>>>>>>>>      void m() {
>>>>>>>>          int z = 0;
>>>>>>>>          record RR(int x) { public int x() { return z; }};
>>>>>>>>      }
>>>>>>>> }
>>>>>>>
>>>>>>> Why is this accepted? Isn't capture of locals also disabled, as 
>>>>>>> demonstrated in the test:
>>>>>>>
>>>>>>> // Cant capture locals
>>>>>>> + assertFail("compiler.err.non-static.cant.be.ref",
>>>>>>> + "class R { \n" +
>>>>>>>                   "    void m(int y) { \n" +
>>>>>>>                   "        record RR(int x) { public int x() { return y; }};\n" +
>>>>>>>                   "    }\n" +
>>>>>>>                   "}");
>>>>>> sorry I should have been more specific. When I said: "with the 
>>>>>> current conditions" in my previous mail I should had said: "with 
>>>>>> current state without the patch this code is accepted" that's 
>>>>>> what I meant. Without the patch access to non-static fields from 
>>>>>> records are banned but access to local variables is not. This 
>>>>>> patch is closing that last gap
>>>>>>
>>>>>> Vicente
>>>>
>>


[Attachment #3 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    ;) sure, good catch<br>
    <br>
    Vicente<br>
    <br>
    <div class="moz-cite-prefix">On 1/14/20 5:49 AM, Maurizio Cimadamore
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:e9d7494b-1534-060b-963f-f58252790834@oracle.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <p>Thanks!</p>
      <p>Maurizio<br>
      </p>
      <div class="moz-cite-prefix">On 14/01/2020 03:37, Vicente Romero
        wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:caf07400-bcae-2948-2c18-ed56b2246ba4@oracle.com">
        <meta http-equiv="Content-Type" content="text/html;
          charset=UTF-8">
        I will add a test in the lines of:<br>
        <br>
        class Outer&lt;T&gt; {<br>
            void m() {<br>
                record R(T t) {}<br>
            }<br>
        }<br>
        <br>
        to the patch<br>
        <br>
        Thanks,<br>
        Vicente<br>
        <br>
        <div class="moz-cite-prefix">On 1/13/20 4:05 PM, Maurizio
          Cimadamore wrote:<br>
        </div>
        <blockquote type="cite"
          cite="mid:b5a575c9-6eb9-fc31-f271-a45683820e31@oracle.com">
          <meta http-equiv="Content-Type" content="text/html;
            charset=UTF-8">
          <p>Maybe too late but we might want to add a test for
            type-variables - e.g. accessing enclosing type-variables
            should equally be banned.</p>
          <p>Maurizio<br>
          </p>
          <div class="moz-cite-prefix">On 13/01/2020 17:46, Vicente
            Romero wrote:<br>
          </div>
          <blockquote type="cite"
            cite="mid:28d36ee0-af69-9a11-63f4-dab199a0257b@oracle.com">
            <meta http-equiv="Content-Type" content="text/html;
              charset=UTF-8">
            <br>
            <br>
            <div class="moz-cite-prefix">On 1/13/20 9:46 AM, Maurizio
              Cimadamore wrote:<br>
            </div>
            <blockquote type="cite"
              cite="mid:66a327aa-bc0a-4039-e328-d1ca97423bd0@oracle.com">
              <meta http-equiv="Content-Type" content="text/html;
                charset=UTF-8">
              <p>Thanks for the explanation. I've convinced myself that
                the code is correct. Basically, if we're trying to
                access a local variable defined in a method whose class
                is != than the current class &amp;&amp; the current
                class is also static (which can only happen with
                records, as that's the only local construct which can
                also be static), an error should be issued.</p>
            </blockquote>
            <br>
            cool thanks,<br>
            <br>
            <blockquote type="cite"
              cite="mid:66a327aa-bc0a-4039-e328-d1ca97423bd0@oracle.com">
              <p>Maurizio<br>
              </p>
            </blockquote>
            <br>
            Vicente<br>
            <br>
            <blockquote type="cite"
              cite="mid:66a327aa-bc0a-4039-e328-d1ca97423bd0@oracle.com">
              <p> </p>
              <div class="moz-cite-prefix">On 13/01/2020 13:39, Vicente
                Romero wrote:<br>
              </div>
              <blockquote type="cite"
                cite="mid:1bf9b149-df64-3a7d-ca1c-2fcf1237eb6d@oracle.com">
                <meta http-equiv="Content-Type" content="text/html;
                  charset=UTF-8">
                <br>
                <br>
                <div class="moz-cite-prefix">On 1/10/20 8:02 PM,
                  Maurizio Cimadamore wrote:<br>
                </div>
                <blockquote type="cite"
                  cite="mid:538d2c1a-7218-9f19-6652-b536718b2dcc@oracle.com">
                  <meta http-equiv="Content-Type" content="text/html;
                    charset=UTF-8">
                  <p><br>
                  </p>
                  <div class="moz-cite-prefix">On 10/01/2020 22:53,
                    Vicente Romero wrote:<br>
                  </div>
                  <blockquote type="cite"
                    cite="mid:60883e1a-6b56-e605-a6c1-f8d4071223b9@oracle.com">
                    <pre \
style="background-color:#ffffff;color:#000000;font-family:'DejaVu Sans \
Mono';font-size:11.3pt;">but this code is accepted:

class R {
    void m() {
        int z = 0;
        record RR(int x) { public int x() { return z; }};
    }
}</pre>
                  </blockquote>
                  <p>Why is this accepted? Isn't capture of locals also
                    disabled, as demonstrated in the test:</p>
                  <pre><span class="new"> // Cant capture locals</span>
<span class="new">+        assertFail("compiler.err.non-static.cant.be.ref",</span>
<span class="new">+                "class R { \n" +</span>
                 "    void m(int y) { \n" +
                 "        record RR(int x) { public int x() { return y; }};\n" +
                 "    }\n" +
                 "}");</pre>
                </blockquote>
                sorry I should have been more specific. When I said:
                "with the current conditions" in my previous mail I
                should had said: "with current state without the patch
                this code is accepted" that's what I meant. Without the
                patch access to non-static fields from records are
                banned but access to local variables is not. This patch
                is closing that last gap<br>
                <br>
                Vicente<br>
              </blockquote>
            </blockquote>
            <br>
          </blockquote>
        </blockquote>
        <br>
      </blockquote>
    </blockquote>
    <br>
  </body>
</html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic