changeset 101:f45b5d2d9639 tip

Fixed a compiler crash on some closures that can't complete normally but which are assigned to a variable of a function type with a primitive result type.
author gafter
date Mon, 11 Aug 2008 19:28:55 -0700
parents cb93e4ee2b57
children
files src/share/classes/com/sun/tools/javac/comp/DeClosure.java src/share/classes/com/sun/tools/javac/comp/Lower.java test/tools/javac/closures/Buckley01.java
diffstat 3 files changed, 51 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/comp/DeClosure.java	Mon Aug 04 02:38:14 2008 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/DeClosure.java	Mon Aug 11 19:28:55 2008 -0700
@@ -1204,10 +1204,11 @@
                 ListBuffer<JCStatement> stats = ListBuffer.lb();
                 if (restype.tag == TypeTags.VOID || restype.tsym == syms.nothingType.tsym) {
                     Type mReturn = mtype.getReturnType();
-                    if (mReturn.tag == TypeTags.VOID || mReturn.tsym == syms.nothingType.tsym) {
-                        stats.add(make.Exec(apply));
-                    } else {
-                        stats.add(make.Exec(apply));
+                    stats.add(make.Exec(apply));
+                    if (restype.tsym == syms.nothingType.tsym) {
+                        stats.add(make.Throw(make.Null()));
+                    } else if (mReturn.tag != TypeTags.VOID && mReturn.tsym != syms.nothingType.tsym) {
+                        assert types.isSubtype(mReturn, syms.objectType);
                         stats.add(make.Return(make.Null()));
                     }
                 } else {
--- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Mon Aug 04 02:38:14 2008 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Mon Aug 11 19:28:55 2008 -0700
@@ -2648,7 +2648,7 @@
     /** Unbox an object to a primitive value. */
     JCExpression unbox(JCExpression tree, Type primitive) {
         Type unboxedType = types.unboxedType(tree.type);
-        // note: the "primitive" parameter is not used.  There muse be
+        // note: the "primitive" parameter is not used.  There must be
         // a conversion from unboxedType to primitive.
         make_at(tree.pos());
         Symbol valueSym = lookupMethod(tree.pos(),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/closures/Buckley01.java	Mon Aug 11 19:28:55 2008 -0700
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2008 Neal M Gafter.  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.  Neal designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+/*
+ * @test
+ * @summary Compiler crash with nonlocal transfers
+ * @author gafter
+ *
+ * @clean Buckley01
+ * @compile -source 7 Buckley01.java
+ * @run main Buckley01
+ */
+
+public class Buckley01 {
+ public static void main(String[] a) {
+   System.out.println(new Buckley01().work());
+ }
+
+ int work() {
+   { ==> int } x = { ==> return 1; };
+   x.invoke();
+   return 2;
+ }
+}