8044534: Constant folding for unary + should produce int for boolean literals
authorattila
Tue, 03 Jun 2014 12:05:42 +0200
changeset 24775 a0ae9045563f
parent 24774 da5a0201be9d
child 24776 966226aeee50
8044534: Constant folding for unary + should produce int for boolean literals Reviewed-by: lagergren, sundar
nashorn/src/jdk/nashorn/internal/codegen/FoldConstants.java
nashorn/test/script/basic/JDK-8044534.js
nashorn/test/script/basic/JDK-8044534.js.EXPECTED
--- a/nashorn/src/jdk/nashorn/internal/codegen/FoldConstants.java	Tue Jun 03 12:04:36 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/codegen/FoldConstants.java	Tue Jun 03 12:05:42 2014 +0200
@@ -27,7 +27,6 @@
 
 import java.util.ArrayList;
 import java.util.List;
-
 import jdk.nashorn.internal.codegen.types.Type;
 import jdk.nashorn.internal.ir.BinaryNode;
 import jdk.nashorn.internal.ir.Block;
@@ -185,7 +184,8 @@
             }
 
             final LiteralNode<?> rhs = (LiteralNode<?>)rhsNode;
-            final boolean rhsInteger = rhs.getType().isInteger();
+            final Type rhsType = rhs.getType();
+            final boolean rhsInteger = rhsType.isInteger() || rhsType.isBoolean();
 
             LiteralNode<?> literalNode;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8044534.js	Tue Jun 03 12:05:42 2014 +0200
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8044534: Constant folding for unary + should produce int for boolean literals
+ *
+ * @test
+ * @run
+ */
+
+var inspect = Java.type("jdk.nashorn.test.tools.StaticTypeInspector").inspect;
+
+print(inspect(+true,  "+true "));
+print(inspect(+false, "+false"));
+print(inspect(-true,  "-true "));
+print(inspect(-false, "-false"));
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8044534.js.EXPECTED	Tue Jun 03 12:05:42 2014 +0200
@@ -0,0 +1,4 @@
++true : int
++false: int
+-true : int
+-false: double