Skip to content
Permalink
Browse files
8263590: Rawtypes warnings should be produced for pattern matching in…
… instanceof

Reviewed-by: mcimadamore
  • Loading branch information
Jan Lahoda committed Mar 18, 2021
1 parent ff52f29 commit 9cd21b687eff3b888375392621068224c0f7f7a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
@@ -3963,6 +3963,7 @@ public void visitTypeTest(JCInstanceOf tree) {
tree.expr.pos(), attribExpr(tree.expr, env));
Type clazztype;
JCTree typeTree;
boolean checkRawTypes;
if (tree.pattern.getTag() == BINDINGPATTERN) {
attribTree(tree.pattern, env, unknownExprInfo);
clazztype = tree.pattern.type;
@@ -3975,9 +3976,11 @@ public void visitTypeTest(JCInstanceOf tree) {
if (!clazztype.hasTag(TYPEVAR)) {
clazztype = chk.checkClassOrArrayType(pattern.var.vartype.pos(), clazztype);
}
checkRawTypes = true;
} else {
clazztype = attribType(tree.pattern, env);
typeTree = tree.pattern;
checkRawTypes = false;
}
if (!clazztype.hasTag(TYPEVAR)) {
clazztype = chk.checkClassOrArrayType(typeTree.pos(), clazztype);
@@ -4007,7 +4010,7 @@ public void visitTypeTest(JCInstanceOf tree) {
clazztype = types.createErrorType(clazztype);
}
}
chk.validate(typeTree, env, false);
chk.validate(typeTree, env, checkRawTypes);
chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
result = check(tree, syms.booleanType, KindSelector.VAL, resultInfo);
}
@@ -0,0 +1,11 @@
/*
* @test /nodynamiccopyright/
* @bug 8263590
* @summary Verify correct warnings are produced for raw types in bindings
* @compile/ref=RawTypeBindingWarning.out -Xlint:rawtypes -XDrawDiagnostics RawTypeBindingWarning.java
*/
public class RawTypeBindingWarning<T> {
public static boolean t(Object o) {
return o instanceof RawTypeBindingWarning w;
}
}
@@ -0,0 +1,2 @@
RawTypeBindingWarning.java:9:29: compiler.warn.raw.class.use: RawTypeBindingWarning, RawTypeBindingWarning<T>
1 warning

0 comments on commit 9cd21b6

Please sign in to comment.