Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2883,7 +2883,7 @@ Symbol resolveDiamond(DiagnosticPosition pos,
new BasicLookupHelper(names.init, site, argtypes, typeargtypes) {
@Override
Symbol doLookup(Env<AttrContext> env, MethodResolutionPhase phase) {
return findDiamond(env, site, argtypes, typeargtypes,
return findDiamond(pos, env, site, argtypes, typeargtypes,
phase.isBoxingRequired(),
phase.isVarargsRequired());
}
Expand All @@ -2906,6 +2906,29 @@ Symbol access(Env<AttrContext> 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<AttrContext> env,
Type site,
List<Type> argtypes,
List<Type> 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,
Expand Down
15 changes: 15 additions & 0 deletions test/langtools/tools/javac/T8257037/T8257037.java
Original file line number Diff line number Diff line change
@@ -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<Object> test = new T8257037_GenericClass<>(); // use diamond
}

class T8257037_GenericClass<T> {
@Deprecated
public T8257037_GenericClass() {}
}
2 changes: 2 additions & 0 deletions test/langtools/tools/javac/T8257037/T8257037.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
T8257037.java:9:42: compiler.warn.has.been.deprecated: <T>T8257037_GenericClass(), T8257037_GenericClass
1 warning