RFR: JDK-8234922: No compilation error reported not reported for a binding variable when loop broken with label
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Dec 2 15:00:54 UTC 2019
Approved
Thanks
Maurizio
On 29/11/2019 11:25, Jan Lahoda wrote:
> On 28. 11. 19 19:43, Maurizio Cimadamore wrote:
>> Looks good - I wonder if we really need to store all trees from the
>> outer loop down to the break statement.
>
> Thanks.
>
>>
>> Shouldn't we just add trees that could potentially be targets of a
>> break? (e.g. labels, switch and other loops)
>
> We can - updated patch:
> http://cr.openjdk.java.net/~jlahoda/8234922/webrev.01/
>
> Thanks,
> Jan
>
>>
>> Maurizio
>>
>> On 28/11/2019 15:11, Jan Lahoda wrote:
>>> Hi,
>>>
>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8234922
>>>
>>> The problem described there is basically:
>>> ---
>>> public class PatternTest {
>>> public static void test(Object o) {
>>> A:
>>> do {
>>> break A;
>>> } while (!(o instanceof String v));
>>> System.out.println("Got: " + v);
>>> }
>>> }
>>> ---
>>>
>>> This should not compile, as "v" should not be in scope for the
>>> System.out.println, but javac fails to detect the break, as the
>>> break breaks to a labeled statement, not to the loop. The proposed
>>> patch solves not only this, but also break to any statement that is
>>> not inside the given loop.
>>>
>>> Webrev:
>>> http://cr.openjdk.java.net/~jlahoda/8234922/webrev.00/
>>>
>>> How does this look?
>>>
>>> Thanks,
>>> Jan
More information about the compiler-dev
mailing list