Skip to content

Commit 1ceb999

Browse files
committed
8257037: No javac warning when calling deprecated constructor with diamond
1 parent 1241f80 commit 1ceb999

File tree

3 files changed

+77
-10
lines changed

3 files changed

+77
-10
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,7 @@ Symbol resolveDiamond(DiagnosticPosition pos,
28832883
new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
28842884
@Override
28852885
Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2886-
return findDiamond(env, site, argtypes, typeargtypes,
2886+
return findDiamond(pos, env, site, argtypes, typeargtypes,
28872887
phase.isBoxingRequired(),
28882888
phase.isVarargsRequired());
28892889
}
@@ -2896,23 +2896,50 @@ Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Sym
28962896
} else {
28972897
final JCDiagnostic details = sym.kind == WRONG_MTH ?
28982898
((InapplicableSymbolError)sym.baseSymbol()).errCandidate().snd :
2899-
null;
2899+
null;
29002900
sym = new DiamondError(sym, currentResolutionContext);
29012901
sym = accessMethod(sym, pos, site, names.init, true, argtypes, typeargtypes);
29022902
env.info.pendingResolutionPhase = currentResolutionContext.step;
29032903
}
29042904
}
29052905
return sym;
2906-
}});
2906+
}
2907+
});
29072908
}
29082909

2909-
/** This method scans all the constructor symbol in a given class scope -
2910-
* assuming that the original scope contains a constructor of the kind:
2911-
* {@code Foo(X x, Y y)}, where X,Y are class type-variables declared in Foo,
2912-
* a method check is executed against the modified constructor type:
2913-
* {@code <X,Y>Foo<X,Y>(X x, Y y)}. This is crucial in order to enable diamond
2914-
* inference. The inferred return type of the synthetic constructor IS
2915-
* the inferred type for the diamond operator.
2910+
/**
2911+
* Find the constructor using diamond inference and do some checks(deprecated and preview).
2912+
*
2913+
* @param pos The position to use for error reporting.
2914+
* @param env The environment current at the constructor invocation.
2915+
* @param site The type of class for which a constructor is searched.
2916+
* The scope of this class has been touched in attribution.
2917+
* @param argtypes The types of the constructor invocation's value arguments.
2918+
* @param typeargtypes The types of the constructor invocation's type arguments.
2919+
* @param allowBoxing Allow boxing conversions of arguments.
2920+
* @param useVarargs Box trailing arguments into an array for varargs.
2921+
*/
2922+
private Symbol findDiamond(DiagnosticPosition pos,
2923+
Env<AttrContext> env,
2924+
Type site,
2925+
List<Type> argtypes,
2926+
List<Type> typeargtypes,
2927+
boolean allowBoxing,
2928+
boolean useVarargs) {
2929+
Symbol sym = findDiamond(env, site, argtypes, typeargtypes, allowBoxing, useVarargs);
2930+
chk.checkDeprecated(pos, env.info.scope.owner, sym);
2931+
chk.checkPreview(pos, sym);
2932+
return sym;
2933+
}
2934+
2935+
/**
2936+
* This method scans all the constructor symbol in a given class scope -
2937+
* assuming that the original scope contains a constructor of the kind:
2938+
* {@code Foo(X x, Y y)}, where X,Y are class type-variables declared in Foo,
2939+
* a method check is executed against the modified constructor type:
2940+
* {@code <X,Y>Foo<X,Y>(X x, Y y)}. This is crucial in order to enable diamond
2941+
* inference. The inferred return type of the synthetic constructor IS
2942+
* the inferred type for the diamond operator.
29162943
*/
29172944
private Symbol findDiamond(Env<AttrContext> env,
29182945
Type site,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8257307
27+
* @summary No javac warning when calling deprecated constructor with diamond
28+
* @run compile/ref=T8257037.out -Xlint -XDrawDiagnostics T8257037.java
29+
*/
30+
31+
public class T8257037 {
32+
T8257037_GenericClass<Object> test = new T8257037_GenericClass<>(); // use diamond
33+
}
34+
35+
class T8257037_GenericClass<T> {
36+
@Deprecated
37+
public T8257037_GenericClass() {}
38+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
T8257037.java:32:42: compiler.warn.has.been.deprecated: <T>T8257037_GenericClass(), T8257037_GenericClass
2+
1 warning

0 commit comments

Comments
 (0)