Mercurial > hg > openjdk > jigsaw > langtools
changeset 829:56f59723fddf
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
author | mcimadamore |
---|---|
date | Mon, 06 Dec 2010 11:50:37 +0000 |
parents | 5fb14e67c371 |
children | 536ee9f126b1 |
files | src/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/multicatch/Neg06.java test/tools/javac/multicatch/Neg06.out |
diffstat | 3 files changed, 28 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Dec 06 11:49:00 2010 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Mon Dec 06 11:50:37 2010 +0000 @@ -2889,8 +2889,15 @@ } public void visitTypeDisjunction(JCTypeDisjunction tree) { - List<Type> alternatives = attribTypes(tree.alternatives, env); - tree.type = result = check(tree, types.lub(alternatives), TYP, pkind, pt); + ListBuffer<Type> multicatchTypes = ListBuffer.lb(); + 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) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/multicatch/Neg06.java Mon Dec 06 11:50:37 2010 +0000 @@ -0,0 +1,16 @@ +/* + * @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) {} + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/multicatch/Neg06.out Mon Dec 06 11:50:37 2010 +0000 @@ -0,0 +1,3 @@ +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