Mon, 29 Sep 2008 11:34:43 +0100
6500343: compiler generates bad code when translating conditional expressions
Summary: TransTypes needs to deal with intersection types coming from conditional expressions
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Tue Sep 23 10:44:51 2008 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Mon Sep 29 11:34:43 2008 +0100 1.3 @@ -534,7 +534,7 @@ 1.4 tree.truepart = translate(tree.truepart, erasure(tree.type)); 1.5 tree.falsepart = translate(tree.falsepart, erasure(tree.type)); 1.6 tree.type = erasure(tree.type); 1.7 - result = tree; 1.8 + result = retype(tree, tree.type, pt); 1.9 } 1.10 1.11 public void visitIf(JCIf tree) {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/conditional/6500343/T6500343a.java Mon Sep 29 11:34:43 2008 +0100 2.3 @@ -0,0 +1,50 @@ 2.4 +/* 2.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 + * have any questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 6500343 2.30 + * @summary compiler generates bad code when translating conditional expressions 2.31 + * @author Maurizio Cimadamore 2.32 + * 2.33 + */ 2.34 + 2.35 +public class T6500343a { 2.36 + static class Base {} 2.37 + static interface I {} 2.38 + static class A1 extends Base implements I {} 2.39 + static class A2 extends Base implements I {} 2.40 + 2.41 + static Object crash(I i, A1 a1, A2 a2, boolean b1, boolean b2) { 2.42 + return b1 ? i : b2 ? a2 : a1; 2.43 + // lub(I, lub(A1, A2)) ==> lub(I, Base&I) ==> I (doesn't compile on 1.4 ok >1.5) 2.44 + } 2.45 + 2.46 + public static void main(String[] args) { 2.47 + T6500343a.crash(new A1(), new A1(), new A2(), true, false); 2.48 + T6500343a.crash(new A1(), new A1(), new A2(), false, true); 2.49 + T6500343a.crash(new A1(), new A1(), new A2(), false, false); 2.50 + T6500343a.crash(new A1(), new A1(), new A2(), true, true); 2.51 + } 2.52 +} 2.53 +
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javac/conditional/6500343/T6500343b.java Mon Sep 29 11:34:43 2008 +0100 3.3 @@ -0,0 +1,48 @@ 3.4 +/* 3.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 3.24 + * have any questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 6500343 3.30 + * @summary compiler generates bad code when translating conditional expressions 3.31 + * @author Maurizio Cimadamore 3.32 + * 3.33 + */ 3.34 + 3.35 +public class T6500343b { 3.36 + 3.37 + final static int i1 = 0; 3.38 + final static int i2 = 1; 3.39 + 3.40 + static void crash(int i) { 3.41 + switch (i) { 3.42 + case (true ? 0 : 1): 3.43 + case (i1 == 5 ? 1 : 2): 3.44 + case (i1 == i2 ? 2 : 3): 3.45 + } 3.46 + } 3.47 + 3.48 + public static void main(String[] args) { 3.49 + T6500343b.crash(0); 3.50 + } 3.51 +}