Skip to content

Commit 45596db

Browse files
author
duke
committedDec 7, 2020
Automatic merge of jdk:master into master
2 parents ea2e240 + 2c04fc0 commit 45596db

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed
 

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

+24-1
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,7 @@ Symbol resolveDiamond(DiagnosticPosition pos,
29192919
new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
29202920
@Override
29212921
Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
2922-
return findDiamond(env, site, argtypes, typeargtypes,
2922+
return findDiamond(pos, env, site, argtypes, typeargtypes,
29232923
phase.isBoxingRequired(),
29242924
phase.isVarargsRequired());
29252925
}
@@ -2942,6 +2942,29 @@ Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Sym
29422942
}});
29432943
}
29442944

2945+
/** Find the constructor using diamond inference and do some checks(deprecated and preview).
2946+
* @param pos The position to use for error reporting.
2947+
* @param env The environment current at the constructor invocation.
2948+
* @param site The type of class for which a constructor is searched.
2949+
* The scope of this class has been touched in attribution.
2950+
* @param argtypes The types of the constructor invocation's value arguments.
2951+
* @param typeargtypes The types of the constructor invocation's type arguments.
2952+
* @param allowBoxing Allow boxing conversions of arguments.
2953+
* @param useVarargs Box trailing arguments into an array for varargs.
2954+
*/
2955+
private Symbol findDiamond(DiagnosticPosition pos,
2956+
Env<AttrContext> env,
2957+
Type site,
2958+
List<Type> argtypes,
2959+
List<Type> typeargtypes,
2960+
boolean allowBoxing,
2961+
boolean useVarargs) {
2962+
Symbol sym = findDiamond(env, site, argtypes, typeargtypes, allowBoxing, useVarargs);
2963+
chk.checkDeprecated(pos, env.info.scope.owner, sym);
2964+
chk.checkPreview(pos, sym);
2965+
return sym;
2966+
}
2967+
29452968
/** This method scans all the constructor symbol in a given class scope -
29462969
* assuming that the original scope contains a constructor of the kind:
29472970
* {@code Foo(X x, Y y)}, where X,Y are class type-variables declared in Foo,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* @test /nodynamiccopyright/
3+
* @bug 8257307
4+
* @summary No javac warning when calling deprecated constructor with diamond
5+
* @run compile/ref=T8257037.out -Xlint -XDrawDiagnostics T8257037.java
6+
*/
7+
8+
public class T8257037 {
9+
T8257037_GenericClass<Object> test = new T8257037_GenericClass<>(); // use diamond
10+
}
11+
12+
class T8257037_GenericClass<T> {
13+
@Deprecated
14+
public T8257037_GenericClass() {}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
T8257037.java:9:42: compiler.warn.has.been.deprecated: <T>T8257037_GenericClass(), T8257037_GenericClass
2+
1 warning

0 commit comments

Comments
 (0)
Please sign in to comment.