8012685: Spurious raw types warning when using unbound method references
Spurious raw type warning when unbound method reference qualifier parameter types are inferred from target Reviewed-by: jjg, vromero
This commit is contained in:
parent
ec458693f7
commit
fc9e870275
@ -2642,10 +2642,11 @@ public class Attr extends JCTree.Visitor {
|
||||
return;
|
||||
}
|
||||
|
||||
if (TreeInfo.isStaticSelector(that.expr, names) &&
|
||||
(that.getMode() != ReferenceMode.NEW || !that.expr.type.isRaw())) {
|
||||
//if the qualifier is a type, validate it
|
||||
chk.validate(that.expr, env);
|
||||
if (TreeInfo.isStaticSelector(that.expr, names)) {
|
||||
//if the qualifier is a type, validate it; raw warning check is
|
||||
//omitted as we don't know at this stage as to whether this is a
|
||||
//raw selector (because of inference)
|
||||
chk.validate(that.expr, env, false);
|
||||
}
|
||||
|
||||
//attrib type-arguments
|
||||
@ -2731,6 +2732,13 @@ public class Attr extends JCTree.Visitor {
|
||||
|
||||
if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) {
|
||||
|
||||
if (that.getMode() == ReferenceMode.INVOKE &&
|
||||
TreeInfo.isStaticSelector(that.expr, names) &&
|
||||
that.kind.isUnbound() &&
|
||||
!desc.getParameterTypes().head.isParameterized()) {
|
||||
chk.checkRaw(that.expr, localEnv);
|
||||
}
|
||||
|
||||
if (!that.kind.isUnbound() &&
|
||||
that.getMode() == ReferenceMode.INVOKE &&
|
||||
TreeInfo.isStaticSelector(that.expr, names) &&
|
||||
|
@ -1361,23 +1361,23 @@ public class Check {
|
||||
for (List<? extends JCTree> l = trees; l.nonEmpty(); l = l.tail)
|
||||
validateTree(l.head, checkRaw, isOuter);
|
||||
}
|
||||
}
|
||||
|
||||
void checkRaw(JCTree tree, Env<AttrContext> env) {
|
||||
if (lint.isEnabled(LintCategory.RAW) &&
|
||||
tree.type.hasTag(CLASS) &&
|
||||
!TreeInfo.isDiamond(tree) &&
|
||||
!withinAnonConstr(env) &&
|
||||
tree.type.isRaw()) {
|
||||
log.warning(LintCategory.RAW,
|
||||
tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type);
|
||||
}
|
||||
void checkRaw(JCTree tree, Env<AttrContext> env) {
|
||||
if (lint.isEnabled(LintCategory.RAW) &&
|
||||
tree.type.hasTag(CLASS) &&
|
||||
!TreeInfo.isDiamond(tree) &&
|
||||
!withinAnonConstr(env) &&
|
||||
tree.type.isRaw()) {
|
||||
log.warning(LintCategory.RAW,
|
||||
tree.pos(), "raw.class.use", tree.type, tree.type.tsym.type);
|
||||
}
|
||||
|
||||
boolean withinAnonConstr(Env<AttrContext> env) {
|
||||
}
|
||||
//where
|
||||
private boolean withinAnonConstr(Env<AttrContext> env) {
|
||||
return env.enclClass.name.isEmpty() &&
|
||||
env.enclMethod != null && env.enclMethod.name == names.init;
|
||||
}
|
||||
}
|
||||
|
||||
/* *************************************************************************
|
||||
* Exception checking
|
||||
|
18
langtools/test/tools/javac/lambda/MethodReference67.java
Normal file
18
langtools/test/tools/javac/lambda/MethodReference67.java
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 8012685
|
||||
* @summary Spurious raw types warning when using unbound method references
|
||||
* @compile/fail/ref=MethodReference67.out -Werror -Xlint:rawtypes -XDrawDiagnostics MethodReference67.java
|
||||
*/
|
||||
import java.util.*;
|
||||
|
||||
class MethodReference67 {
|
||||
interface Foo<X> {
|
||||
void m(List<X> lx, X x);
|
||||
}
|
||||
|
||||
void test() {
|
||||
Foo<String> fs1 = List::add; //no raw warnings here!
|
||||
Foo fs2 = List::add;
|
||||
}
|
||||
}
|
7
langtools/test/tools/javac/lambda/MethodReference67.out
Normal file
7
langtools/test/tools/javac/lambda/MethodReference67.out
Normal file
@ -0,0 +1,7 @@
|
||||
MethodReference67.java:16:9: compiler.warn.raw.class.use: MethodReference67.Foo, MethodReference67.Foo<X>
|
||||
MethodReference67.java:16:19: compiler.warn.raw.class.use: java.util.List, java.util.List<E>
|
||||
- compiler.err.warnings.and.werror
|
||||
- compiler.note.unchecked.filename: MethodReference67.java
|
||||
- compiler.note.unchecked.recompile
|
||||
1 error
|
||||
2 warnings
|
Loading…
x
Reference in New Issue
Block a user