Skip to content

Commit

Permalink
8257037: No javac warning when calling deprecated constructor with di…
Browse files Browse the repository at this point in the history
…amond

Reviewed-by: mcimadamore
  • Loading branch information
lgxbslgx authored and mcimadamore committed Dec 7, 2020
1 parent 46b35ac commit 2c04fc0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2919,7 +2919,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 @@ -2942,6 +2942,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

1 comment on commit 2c04fc0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.