aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlagergren <none@none>2013-07-05 19:35:39 +0200
committerlagergren <none@none>2013-07-05 19:35:39 +0200
commitc929d91bce6bc017c6319f11a6eb7b8296fb4c22 (patch)
tree31da5ef7d92597c7ad6c5541618dff3b80402b24
parentfa9fb4c8e35198c53137d269be867c519bcf3166 (diff)
downloadjdk8u_nashorn-c929d91bce6bc017c6319f11a6eb7b8296fb4c22.tar.gz
8019983: Void returns combined with return with expression picked the wrong return type
Reviewed-by: sundar, jlaskey
-rw-r--r--src/jdk/nashorn/internal/codegen/Attr.java9
-rw-r--r--test/script/basic/JDK-8019983.js42
-rw-r--r--test/script/basic/JDK-8019983.js.EXPECTED1
3 files changed, 49 insertions, 3 deletions
diff --git a/src/jdk/nashorn/internal/codegen/Attr.java b/src/jdk/nashorn/internal/codegen/Attr.java
index 60de4255..6dbfa6d4 100644
--- a/src/jdk/nashorn/internal/codegen/Attr.java
+++ b/src/jdk/nashorn/internal/codegen/Attr.java
@@ -749,6 +749,7 @@ final class Attr extends NodeOperatorVisitor<LexicalContext> {
@Override
public Node leaveReturnNode(final ReturnNode returnNode) {
final Node expr = returnNode.getExpression();
+ final Type returnType;
if (expr != null) {
//we can't do parameter specialization if we return something that hasn't been typed yet
@@ -757,10 +758,12 @@ final class Attr extends NodeOperatorVisitor<LexicalContext> {
symbol.setType(Type.OBJECT);
}
- final Type returnType = Type.widest(returnTypes.pop(), symbol.getSymbolType());
- returnTypes.push(returnType);
- LOG.info("Returntype is now ", returnType);
+ returnType = Type.widest(returnTypes.pop(), symbol.getSymbolType());
+ } else {
+ returnType = Type.OBJECT; //undefined
}
+ LOG.info("Returntype is now ", returnType);
+ returnTypes.push(returnType);
end(returnNode);
diff --git a/test/script/basic/JDK-8019983.js b/test/script/basic/JDK-8019983.js
new file mode 100644
index 00000000..7851ab01
--- /dev/null
+++ b/test/script/basic/JDK-8019983.js
@@ -0,0 +1,42 @@
+/*
+ * 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-8019983.js return without expression combined with return with expression should produce object
+ * return type (undefined)
+ *
+ * @test
+ * @run
+ */
+
+
+function g() {
+ switch(1) {
+ case 0:
+ case '':
+ default:
+ return;
+ }
+ return 10;
+}
+print(g());
diff --git a/test/script/basic/JDK-8019983.js.EXPECTED b/test/script/basic/JDK-8019983.js.EXPECTED
new file mode 100644
index 00000000..417b7b53
--- /dev/null
+++ b/test/script/basic/JDK-8019983.js.EXPECTED
@@ -0,0 +1 @@
+undefined