提交 ce72c523 编写于 作者: M mcimadamore

7002070: If catch clause has an incompatible type, error pointer points to...

7002070: If catch clause has an incompatible type, error pointer points to first exception type in list
Summary: Attribution should check each component of a disjunctive type separately, rather than checking the corresponding lub()
Reviewed-by: jjg
上级 39fb2b9d
...@@ -2889,8 +2889,15 @@ public class Attr extends JCTree.Visitor { ...@@ -2889,8 +2889,15 @@ public class Attr extends JCTree.Visitor {
} }
public void visitTypeDisjunction(JCTypeDisjunction tree) { public void visitTypeDisjunction(JCTypeDisjunction tree) {
List<Type> alternatives = attribTypes(tree.alternatives, env); ListBuffer<Type> multicatchTypes = ListBuffer.lb();
tree.type = result = check(tree, types.lub(alternatives), TYP, pkind, pt); for (JCExpression typeTree : tree.alternatives) {
Type ctype = attribType(typeTree, env);
ctype = chk.checkType(typeTree.pos(),
chk.checkClassType(typeTree.pos(), ctype),
syms.throwableType);
multicatchTypes.append(ctype);
}
tree.type = result = check(tree, types.lub(multicatchTypes.toList()), TYP, pkind, pt);
} }
public void visitTypeParameter(JCTypeParameter tree) { public void visitTypeParameter(JCTypeParameter tree) {
......
/*
* @test /nodynamiccopyright/
* @bug 7002070
*
* @summary If catch clause has an incompatible type, error pointer points to first exception type in list
* @author mcimadamore
* @compile/fail/ref=Neg06.out -XDrawDiagnostics Neg06.java
*
*/
class Neg06 {
void test() {
try { }
catch (String | Integer s) {}
}
}
Neg06.java:14:16: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.String, java.lang.Throwable
Neg06.java:14:25: compiler.err.prob.found.req: (compiler.misc.incompatible.types), java.lang.Integer, java.lang.Throwable
2 errors
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册