Skip to content

Commit 9cd21b6

Browse files
committed
8263590: Rawtypes warnings should be produced for pattern matching in instanceof
Reviewed-by: mcimadamore
1 parent ff52f29 commit 9cd21b6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3963,6 +3963,7 @@ public void visitTypeTest(JCInstanceOf tree) {
39633963
tree.expr.pos(), attribExpr(tree.expr, env));
39643964
Type clazztype;
39653965
JCTree typeTree;
3966+
boolean checkRawTypes;
39663967
if (tree.pattern.getTag() == BINDINGPATTERN) {
39673968
attribTree(tree.pattern, env, unknownExprInfo);
39683969
clazztype = tree.pattern.type;
@@ -3975,9 +3976,11 @@ public void visitTypeTest(JCInstanceOf tree) {
39753976
if (!clazztype.hasTag(TYPEVAR)) {
39763977
clazztype = chk.checkClassOrArrayType(pattern.var.vartype.pos(), clazztype);
39773978
}
3979+
checkRawTypes = true;
39783980
} else {
39793981
clazztype = attribType(tree.pattern, env);
39803982
typeTree = tree.pattern;
3983+
checkRawTypes = false;
39813984
}
39823985
if (!clazztype.hasTag(TYPEVAR)) {
39833986
clazztype = chk.checkClassOrArrayType(typeTree.pos(), clazztype);
@@ -4007,7 +4010,7 @@ public void visitTypeTest(JCInstanceOf tree) {
40074010
clazztype = types.createErrorType(clazztype);
40084011
}
40094012
}
4010-
chk.validate(typeTree, env, false);
4013+
chk.validate(typeTree, env, checkRawTypes);
40114014
chk.checkCastable(tree.expr.pos(), exprtype, clazztype);
40124015
result = check(tree, syms.booleanType, KindSelector.VAL, resultInfo);
40134016
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* @test /nodynamiccopyright/
3+
* @bug 8263590
4+
* @summary Verify correct warnings are produced for raw types in bindings
5+
* @compile/ref=RawTypeBindingWarning.out -Xlint:rawtypes -XDrawDiagnostics RawTypeBindingWarning.java
6+
*/
7+
public class RawTypeBindingWarning<T> {
8+
public static boolean t(Object o) {
9+
return o instanceof RawTypeBindingWarning w;
10+
}
11+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RawTypeBindingWarning.java:9:29: compiler.warn.raw.class.use: RawTypeBindingWarning, RawTypeBindingWarning<T>
2+
1 warning

0 commit comments

Comments
 (0)