File tree Expand file tree Collapse file tree 4 files changed +39
-8
lines changed
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/tree Expand file tree Collapse file tree 4 files changed +39
-8
lines changed Original file line number Diff line number Diff line change @@ -365,10 +365,6 @@ abstract class RedundantLocalVarTypeAnalyzerBase<X extends JCStatement> extends
365365 super (AnalyzerMode .LOCAL , tag );
366366 }
367367
368- boolean isImplicitlyTyped (JCVariableDecl decl ) {
369- return decl .vartype .pos == Position .NOPOS ;
370- }
371-
372368 /**
373369 * Map a variable tree into a new declaration using implicit type.
374370 */
@@ -401,7 +397,7 @@ class RedundantLocalVarTypeAnalyzer extends RedundantLocalVarTypeAnalyzerBase<JC
401397
402398 boolean match (JCVariableDecl tree ){
403399 return tree .sym .owner .kind == Kind .MTH &&
404- tree .init != null && !isImplicitlyTyped ( tree ) &&
400+ tree .init != null && !tree . declaredUsingVar ( ) &&
405401 attr .canInferLocalVarType (tree ) == null ;
406402 }
407403 @ Override
@@ -425,7 +421,7 @@ class RedundantLocalVarTypeAnalyzerForEach extends RedundantLocalVarTypeAnalyzer
425421
426422 @ Override
427423 boolean match (JCEnhancedForLoop tree ){
428- return !isImplicitlyTyped ( tree .var );
424+ return !tree .var . declaredUsingVar ( );
429425 }
430426 @ Override
431427 List <JCEnhancedForLoop > rewrite (JCEnhancedForLoop oldTree ) {
Original file line number Diff line number Diff line change @@ -5716,9 +5716,9 @@ private Type capture(Type type) {
57165716
57175717 private void setSyntheticVariableType (JCVariableDecl tree , Type type ) {
57185718 if (type .isErroneous ()) {
5719- tree .vartype = make .at (Position . NOPOS ).Erroneous ();
5719+ tree .vartype = make .at (tree . pos () ).Erroneous ();
57205720 } else {
5721- tree .vartype = make .at (Position . NOPOS ).Type (type );
5721+ tree .vartype = make .at (tree . pos () ).Type (type );
57225722 }
57235723 }
57245724
Original file line number Diff line number Diff line change 1+ /*
2+ * @test /nodynamiccopyright/
3+ * @bug 8329951
4+ * @summary Check that "var" variable synthetic types have a source position
5+ * @compile/process/ref=VarWarnPosition.out -Xlint:deprecation -XDrawDiagnostics VarWarnPosition.java
6+ */
7+
8+ import java .util .*;
9+ import java .util .function .*;
10+
11+ public class VarWarnPosition {
12+
13+ VarWarnPosition () {
14+
15+ // Test 1
16+ @ SuppressWarnings ("deprecation" )
17+ List <Depr > deprecatedList = null ;
18+ for (var deprValue : deprecatedList ) { }
19+
20+ // Test 2
21+ Consumer <Depr > c = d -> { };
22+
23+ // Test 3
24+ Consumer <Depr > c2 = (var d ) -> { };
25+ }
26+ }
27+
28+ @ Deprecated
29+ class Depr {}
Original file line number Diff line number Diff line change 1+ VarWarnPosition.java:18:14: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
2+ VarWarnPosition.java:21:18: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
3+ VarWarnPosition.java:21:28: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
4+ VarWarnPosition.java:24:18: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
5+ VarWarnPosition.java:24:30: compiler.warn.has.been.deprecated: Depr, compiler.misc.unnamed.package
6+ 5 warnings
You can’t perform that action at this time.
0 commit comments