Merge branch 'JDK-8329951' into JDK-8348611

This commit is contained in:
Archie L. Cobbs 2025-04-10 11:40:21 -05:00
commit 6852ed1bcb
4 changed files with 33 additions and 3 deletions

View File

@ -366,7 +366,7 @@ public class Analyzer {
}
boolean isImplicitlyTyped(JCVariableDecl decl) {
return decl.vartype.pos == Position.NOPOS;
return decl.declaredUsingVar();
}
/**

View File

@ -5693,9 +5693,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);
}
}

View File

@ -0,0 +1,26 @@
/*
* @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 -> { };
}
}
@Deprecated
class Depr {}

View File

@ -0,0 +1,4 @@
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
3 warnings