# HG changeset patch # User attila # Date 1401789942 -7200 # Node ID a0ae9045563f2539ad04942621927806f96fc14d # Parent da5a0201be9d58ed564d88dabd5ad97590502cb9 8044534: Constant folding for unary + should produce int for boolean literals Reviewed-by: lagergren, sundar diff -r da5a0201be9d -r a0ae9045563f nashorn/src/jdk/nashorn/internal/codegen/FoldConstants.java --- 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; diff -r da5a0201be9d -r a0ae9045563f nashorn/test/script/basic/JDK-8044534.js --- /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")); diff -r da5a0201be9d -r a0ae9045563f nashorn/test/script/basic/JDK-8044534.js.EXPECTED --- /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