8329951: var
emits deprecation warnings that do not point to the file or position
Reviewed-by: vromero
This commit is contained in:
parent
d3f54dae30
commit
e2f736658f
@ -365,10 +365,6 @@ public class Analyzer {
|
||||
super(AnalyzerMode.LOCAL, tag);
|
||||
}
|
||||
|
||||
boolean isImplicitlyTyped(JCVariableDecl decl) {
|
||||
return decl.vartype.pos == Position.NOPOS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a variable tree into a new declaration using implicit type.
|
||||
*/
|
||||
@ -401,7 +397,7 @@ public class Analyzer {
|
||||
|
||||
boolean match(JCVariableDecl tree){
|
||||
return tree.sym.owner.kind == Kind.MTH &&
|
||||
tree.init != null && !isImplicitlyTyped(tree) &&
|
||||
tree.init != null && !tree.declaredUsingVar() &&
|
||||
attr.canInferLocalVarType(tree) == null;
|
||||
}
|
||||
@Override
|
||||
@ -425,7 +421,7 @@ public class Analyzer {
|
||||
|
||||
@Override
|
||||
boolean match(JCEnhancedForLoop tree){
|
||||
return !isImplicitlyTyped(tree.var);
|
||||
return !tree.var.declaredUsingVar();
|
||||
}
|
||||
@Override
|
||||
List<JCEnhancedForLoop> rewrite(JCEnhancedForLoop oldTree) {
|
||||
|
@ -5716,9 +5716,9 @@ public class Attr extends JCTree.Visitor {
|
||||
|
||||
private void setSyntheticVariableType(JCVariableDecl tree, Type type) {
|
||||
if (type.isErroneous()) {
|
||||
tree.vartype = make.at(Position.NOPOS).Erroneous();
|
||||
tree.vartype = make.at(tree.pos()).Erroneous();
|
||||
} else {
|
||||
tree.vartype = make.at(Position.NOPOS).Type(type);
|
||||
tree.vartype = make.at(tree.pos()).Type(type);
|
||||
}
|
||||
}
|
||||
|
||||
|
29
test/langtools/tools/javac/tree/VarWarnPosition.java
Normal file
29
test/langtools/tools/javac/tree/VarWarnPosition.java
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8329951
|
||||
* @summary Check that "var" variable synthetic types have a source position
|
||||
* @compile/process/ref=VarWarnPosition.out -Xlint:deprecation -XDrawDiagnostics VarWarnPosition.java
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
||||
public class VarWarnPosition {
|
||||
|
||||
VarWarnPosition() {
|
||||
|
||||
// Test 1
|
||||
@SuppressWarnings("deprecation")
|
||||
List<Depr> deprecatedList = null;
|
||||
for (var deprValue : deprecatedList) { }
|
||||
|
||||
// Test 2
|
||||
Consumer<Depr> c = d -> { };
|
||||
|
||||
// Test 3
|
||||
Consumer<Depr> c2 = (var d) -> { };
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
class Depr {}
|
6
test/langtools/tools/javac/tree/VarWarnPosition.out
Normal file
6
test/langtools/tools/javac/tree/VarWarnPosition.out
Normal file
@ -0,0 +1,6 @@
|
||||
VarWarnPosition.java:18:14: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
|
||||
VarWarnPosition.java:21:18: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
|
||||
VarWarnPosition.java:21:28: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
|
||||
VarWarnPosition.java:24:18: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
|
||||
VarWarnPosition.java:24:30: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
|
||||
5 warnings
|
Loading…
x
Reference in New Issue
Block a user