changeset 68:e7a8bdf18063

1. The closure conversion from an unrestricted closure to a restricted type doesn't exist. It used to exist as a conversion but generate an error, which had unfortunate effects on overload resolution. 2. Eta expressions produce restricted closures.
author gafter
date Mon, 07 Jul 2008 00:51:51 -0700
parents b965e47522e3
children ba0c588680a8
files src/share/classes/com/sun/tools/javac/code/Type.java src/share/classes/com/sun/tools/javac/code/Types.java test/tools/javac/closures/Mahieu19.java
diffstat 3 files changed, 71 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Type.java	Sun Jul 06 23:16:15 2008 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Mon Jul 07 00:51:51 2008 -0700
@@ -825,7 +825,7 @@
                           Type restype,
                           List<Type> thrown,
                           TypeSymbol methodClass) {
-            this(argtypes, restype, thrown, methodClass, false);
+            this(argtypes, restype, thrown, methodClass, true);
         }
         public MethodType(List<Type> argtypes,
                           Type restype,
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Sun Jul 06 23:16:15 2008 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Mon Jul 07 00:51:51 2008 -0700
@@ -448,6 +448,9 @@
                 if ((cts.tsym.flags() & Flags.INTERFACE) == 0)
 		    return false;
 
+                if (!t.restricted && isSubtype(s, syms.restrictedFunctionType))
+                    return false;
+
                 // ... that has a single abstract method ...
                 List<MethodSymbol> lm = findUniqueAbstracts(cts);
                 if (lm.size() != 1) return false;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/closures/Mahieu19.java	Mon Jul 07 00:51:51 2008 -0700
@@ -0,0 +1,67 @@
+/*
+ * 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 no closure conversion exists from an unrestricted closure to a restricted type
+ * @author gafter
+ *
+ * @clean Mahieu19
+ * @compile -source 7 Mahieu19.java
+ * @run Mahieu19
+ */
+
+public class Mahieu19 {
+    public static void main(String[] args) {
+               
+	@Shared int restrictedCount = 0;
+	int unrestrictedCount = 0;
+               
+	{=>void} restricted = {=> restrictedCount++; };
+	{==>void} unrestricted = {==> unrestrictedCount++; };
+               
+	foo(restricted);
+	foo(unrestricted);
+               
+	foo({=> restrictedCount++; });
+	foo({==> unrestrictedCount++; });  // fails to compile
+               
+	foo() {  // fails to compile
+	    unrestrictedCount++;
+	}
+               
+	if (restrictedCount != 2)
+	    throw new AssertionError();
+	if (unrestrictedCount != 3)
+	    throw new AssertionError();
+    }
+       
+    static void foo({=>void} block) {
+	block.invoke();
+    }
+       
+    static void foo({==>void} block) {
+	block.invoke();
+    }
+}