8156180: javac accepts code that violates JLS chapter 16
DA/DU analysis should skip parenthesis around variable references Reviewed-by: vromero
This commit is contained in:
parent
7fa26cbc1e
commit
f18045ee0b
langtools
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/tools/javac/DefiniteAssignment/8156180
@ -2345,10 +2345,11 @@ public class Flow {
|
||||
// assigned before reading their value
|
||||
public void visitSelect(JCFieldAccess tree) {
|
||||
super.visitSelect(tree);
|
||||
JCTree sel = TreeInfo.skipParens(tree.selected);
|
||||
if (enforceThisDotInit &&
|
||||
tree.selected.hasTag(IDENT) &&
|
||||
((JCIdent)tree.selected).name == names._this &&
|
||||
tree.sym.kind == VAR) {
|
||||
sel.hasTag(IDENT) &&
|
||||
((JCIdent)sel).name == names._this &&
|
||||
tree.sym.kind == VAR) {
|
||||
checkInit(tree.pos(), (VarSymbol)tree.sym);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8156180
|
||||
* @summary javac accepts code that violates JLS chapter 16
|
||||
*
|
||||
* @compile/fail/ref=T8156180.out -XDrawDiagnostics T8156180.java
|
||||
*/
|
||||
|
||||
class T8156180 {
|
||||
public final int a1, b1, c1, d1;
|
||||
public int a2, b2, c2, d2;
|
||||
|
||||
T8156180(int value) {
|
||||
a2 = this.a1;
|
||||
b2 = (this).b1;
|
||||
c2 = ((this)).c1;
|
||||
d2 = (((this))).d1;
|
||||
a1 = value;
|
||||
b1 = value;
|
||||
c1 = value;
|
||||
d1 = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
T8156180.java:14:18: compiler.err.var.might.not.have.been.initialized: a1
|
||||
T8156180.java:15:20: compiler.err.var.might.not.have.been.initialized: b1
|
||||
T8156180.java:16:22: compiler.err.var.might.not.have.been.initialized: c1
|
||||
T8156180.java:17:24: compiler.err.var.might.not.have.been.initialized: d1
|
||||
4 errors
|
Loading…
x
Reference in New Issue
Block a user