提交 c1f40211 编写于 作者: M mcimadamore

8012685: Spurious raw types warning when using unbound method references

Summary: Spurious raw type warning when unbound method reference qualifier parameter types are inferred from target
Reviewed-by: jjg, vromero
上级 67bc5fa1
......@@ -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
......
/*
* @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;
}
}
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册