Tue, 11 Nov 2014 17:27:44 +0100
8062799: Binary logical expressions can have numeric types
Reviewed-by: lagergren, sundar
1.1 --- a/src/jdk/nashorn/internal/ir/BinaryNode.java Tue Nov 11 16:17:37 2014 +0100 1.2 +++ b/src/jdk/nashorn/internal/ir/BinaryNode.java Tue Nov 11 17:27:44 2014 +0100 1.3 @@ -264,6 +264,10 @@ 1.4 case COMMARIGHT: { 1.5 return rhs.getType(localVariableTypes); 1.6 } 1.7 + case AND: 1.8 + case OR:{ 1.9 + return Type.widestReturnType(lhs.getType(localVariableTypes), rhs.getType(localVariableTypes)); 1.10 + } 1.11 default: 1.12 if (isComparison()) { 1.13 return Type.BOOLEAN;
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/script/basic/JDK-8062799.js Tue Nov 11 17:27:44 2014 +0100 2.3 @@ -0,0 +1,103 @@ 2.4 +/* 2.5 + * Copyright (c) 2014 Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/** 2.28 + * JDK-8062799: Binary logical expressions can have numeric types 2.29 + * 2.30 + * @test 2.31 + * @run 2.32 + */ 2.33 + 2.34 +(function() { 2.35 + var inspect = Java.type("jdk.nashorn.test.tools.StaticTypeInspector").inspect; 2.36 + 2.37 + var b = true; 2.38 + var i = 1; 2.39 + var l = 4294967296; 2.40 + var d = 2.1; 2.41 + var o = "foo"; 2.42 + 2.43 + print(inspect(b || b, "b || b")); 2.44 + print(inspect(b || i, "b || i")); 2.45 + print(inspect(b || l, "b || l")); 2.46 + print(inspect(b || d, "b || d")); 2.47 + print(inspect(b || o, "b || o")); 2.48 + 2.49 + print(inspect(i || b, "i || b")); 2.50 + print(inspect(i || i, "i || i")); 2.51 + print(inspect(i || l, "i || l")); 2.52 + print(inspect(i || d, "i || d")); 2.53 + print(inspect(i || o, "i || o")); 2.54 + 2.55 + print(inspect(l || b, "l || b")); 2.56 + print(inspect(l || i, "l || i")); 2.57 + print(inspect(l || l, "l || l")); 2.58 + print(inspect(l || d, "l || d")); 2.59 + print(inspect(l || o, "l || o")); 2.60 + 2.61 + print(inspect(d || b, "d || b")); 2.62 + print(inspect(d || i, "d || i")); 2.63 + print(inspect(d || l, "d || l")); 2.64 + print(inspect(d || d, "d || d")); 2.65 + print(inspect(d || o, "d || o")); 2.66 + 2.67 + print(inspect(o || b, "o || b")); 2.68 + print(inspect(o || i, "o || i")); 2.69 + print(inspect(o || l, "o || l")); 2.70 + print(inspect(o || d, "o || d")); 2.71 + print(inspect(o || o, "o || o")); 2.72 + 2.73 + print(inspect(b && b, "b && b")); 2.74 + print(inspect(b && i, "b && i")); 2.75 + print(inspect(b && l, "b && l")); 2.76 + print(inspect(b && d, "b && d")); 2.77 + print(inspect(b && o, "b && o")); 2.78 + 2.79 + print(inspect(i && b, "i && b")); 2.80 + print(inspect(i && i, "i && i")); 2.81 + print(inspect(i && l, "i && l")); 2.82 + print(inspect(i && d, "i && d")); 2.83 + print(inspect(i && o, "i && o")); 2.84 + 2.85 + print(inspect(l && b, "l && b")); 2.86 + print(inspect(l && i, "l && i")); 2.87 + print(inspect(l && l, "l && l")); 2.88 + print(inspect(l && d, "l && d")); 2.89 + print(inspect(l && o, "l && o")); 2.90 + 2.91 + print(inspect(d && b, "d && b")); 2.92 + print(inspect(d && i, "d && i")); 2.93 + print(inspect(d && l, "d && l")); 2.94 + print(inspect(d && d, "d && d")); 2.95 + print(inspect(d && o, "d && o")); 2.96 + 2.97 + print(inspect(o && b, "o && b")); 2.98 + print(inspect(o && i, "o && i")); 2.99 + print(inspect(o && l, "o && l")); 2.100 + print(inspect(o && d, "o && d")); 2.101 + print(inspect(o && o, "o && o")); 2.102 +})(); 2.103 + 2.104 + 2.105 + 2.106 + 2.107 \ No newline at end of file
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/script/basic/JDK-8062799.js.EXPECTED Tue Nov 11 17:27:44 2014 +0100 3.3 @@ -0,0 +1,50 @@ 3.4 +b || b: boolean 3.5 +b || i: boolean 3.6 +b || l: boolean 3.7 +b || d: boolean 3.8 +b || o: boolean 3.9 +i || b: int 3.10 +i || i: int 3.11 +i || l: long 3.12 +i || d: double 3.13 +i || o: int 3.14 +l || b: long 3.15 +l || i: long 3.16 +l || l: long 3.17 +l || d: double 3.18 +l || o: long 3.19 +d || b: double 3.20 +d || i: double 3.21 +d || l: double 3.22 +d || d: double 3.23 +d || o: double 3.24 +o || b: object 3.25 +o || i: object 3.26 +o || l: object 3.27 +o || d: object 3.28 +o || o: object 3.29 +b && b: boolean 3.30 +b && i: int 3.31 +b && l: long 3.32 +b && d: double 3.33 +b && o: object 3.34 +i && b: boolean 3.35 +i && i: int 3.36 +i && l: long 3.37 +i && d: double 3.38 +i && o: object 3.39 +l && b: boolean 3.40 +l && i: long 3.41 +l && l: long 3.42 +l && d: double 3.43 +l && o: object 3.44 +d && b: boolean 3.45 +d && i: double 3.46 +d && l: double 3.47 +d && d: double 3.48 +d && o: object 3.49 +o && b: boolean 3.50 +o && i: int 3.51 +o && l: long 3.52 +o && d: double 3.53 +o && o: object