diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java index 727d2989adf4b..e519043d96c39 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -2883,7 +2883,7 @@ Symbol resolveDiamond(DiagnosticPosition pos, new BasicLookupHelper(names.init, site, argtypes, typeargtypes) { @Override Symbol doLookup(Env env, MethodResolutionPhase phase) { - return findDiamond(env, site, argtypes, typeargtypes, + return findDiamond(pos, env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()); } @@ -2906,6 +2906,29 @@ Symbol access(Env env, DiagnosticPosition pos, Symbol location, Sym }}); } + /** Find the constructor using diamond inference and do some checks(deprecated and preview). + * @param pos The position to use for error reporting. + * @param env The environment current at the constructor invocation. + * @param site The type of class for which a constructor is searched. + * The scope of this class has been touched in attribution. + * @param argtypes The types of the constructor invocation's value arguments. + * @param typeargtypes The types of the constructor invocation's type arguments. + * @param allowBoxing Allow boxing conversions of arguments. + * @param useVarargs Box trailing arguments into an array for varargs. + */ + private Symbol findDiamond(DiagnosticPosition pos, + Env env, + Type site, + List argtypes, + List typeargtypes, + boolean allowBoxing, + boolean useVarargs) { + Symbol sym = findDiamond(env, site, argtypes, typeargtypes, allowBoxing, useVarargs); + chk.checkDeprecated(pos, env.info.scope.owner, sym); + chk.checkPreview(pos, sym); + return sym; + } + /** This method scans all the constructor symbol in a given class scope - * assuming that the original scope contains a constructor of the kind: * {@code Foo(X x, Y y)}, where X,Y are class type-variables declared in Foo, diff --git a/test/langtools/tools/javac/T8257037/T8257037.java b/test/langtools/tools/javac/T8257037/T8257037.java new file mode 100644 index 0000000000000..cb2730c683892 --- /dev/null +++ b/test/langtools/tools/javac/T8257037/T8257037.java @@ -0,0 +1,15 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8257307 + * @summary No javac warning when calling deprecated constructor with diamond + * @run compile/ref=T8257037.out -Xlint -XDrawDiagnostics T8257037.java + */ + +public class T8257037 { + T8257037_GenericClass test = new T8257037_GenericClass<>(); // use diamond +} + +class T8257037_GenericClass { + @Deprecated + public T8257037_GenericClass() {} +} diff --git a/test/langtools/tools/javac/T8257037/T8257037.out b/test/langtools/tools/javac/T8257037/T8257037.out new file mode 100644 index 0000000000000..b5def45e5c37d --- /dev/null +++ b/test/langtools/tools/javac/T8257037/T8257037.out @@ -0,0 +1,2 @@ +T8257037.java:9:42: compiler.warn.has.been.deprecated: T8257037_GenericClass(), T8257037_GenericClass +1 warning