mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-19 14:55:17 +00:00
8294461: wrong effectively final determination by javac
Reviewed-by: vromero
This commit is contained in:
parent
d6678952a6
commit
b8ad6cd98a
@ -2006,14 +2006,13 @@ public class Flow {
|
||||
void letInit(DiagnosticPosition pos, VarSymbol sym) {
|
||||
if (sym.adr >= firstadr && trackable(sym)) {
|
||||
if ((sym.flags() & EFFECTIVELY_FINAL) != 0) {
|
||||
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
|
||||
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
|
||||
sym.flags_field &= ~EFFECTIVELY_FINAL;
|
||||
} else {
|
||||
uninit(sym);
|
||||
}
|
||||
uninit(sym);
|
||||
}
|
||||
else if ((sym.flags() & FINAL) != 0) {
|
||||
if ((sym.flags() & PARAMETER) != 0) {
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* @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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
EffectivelyFinalLoopIncrement.java:10:51: compiler.err.cant.ref.non.effectively.final.var: i, (compiler.misc.lambda)
|
||||
1 error
|
||||
Loading…
x
Reference in New Issue
Block a user