8299849: Revert JDK-8294461: wrong effectively final determination by javac

Reviewed-by: vromero
This commit is contained in:
Jan Lahoda 2023-01-11 07:52:18 +00:00
parent 0abb87a488
commit 636976ada8
3 changed files with 6 additions and 21 deletions
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/lambda/8294461

@ -2027,13 +2027,14 @@ public class Flow {
void letInit(DiagnosticPosition pos, VarSymbol sym) {
if (sym.adr >= firstadr && trackable(sym)) {
if ((sym.flags() & EFFECTIVELY_FINAL) != 0) {
if (inits.isMember(sym.adr) || !uninits.isMember(sym.adr)) {
//assignment targeting an effectively final variable makes the
//variable lose its status of effectively final if the variable
//is definitely assigned or _not_ definitively unassigned
if (!uninits.isMember(sym.adr)) {
//assignment targeting an effectively final variable
//makes the variable lose its status of effectively final
//if the variable is _not_ definitively unassigned
sym.flags_field &= ~EFFECTIVELY_FINAL;
} else {
uninit(sym);
}
uninit(sym);
}
else if ((sym.flags() & FINAL) != 0) {
if ((sym.flags() & PARAMETER) != 0) {

@ -1,14 +0,0 @@
/*
* @test /nodynamiccopyright/
* @summary Verify for() loop variable not effectively final even if loop never increments
* @bug 8294461
* @compile/fail/ref=EffectivelyFinalLoopIncrement.out -XDrawDiagnostics EffectivelyFinalLoopIncrement.java
*/
class EffectivelyFinalLoopIncrement {
EffectivelyFinalLoopIncrement() {
for (int i = 0; i < 10; i++) {
Runnable r = () -> System.out.println(i); // variable i is NOT effectively final
break; // even though "i++" is never reached
}
}
}

@ -1,2 +0,0 @@
EffectivelyFinalLoopIncrement.java:10:51: compiler.err.cant.ref.non.effectively.final.var: i, (compiler.misc.lambda)
1 error