changeset 67:b965e47522e3

The type of a closure should be reported with the appropriate token depending on whether it was written as a restricted closure or not. Fix a small regression involving captured return types.
author gafter
date Sun, 06 Jul 2008 23:16:15 -0700
parents 0c9fdfcbeb0a
children e7a8bdf18063 4e7153d64341
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/Mahieu17.java test/tools/javac/closures/Mahieu18.java test/tools/javac/closures/Mahieu18.out
diffstat 5 files changed, 64 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Type.java	Sun Jul 06 22:25:06 2008 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Sun Jul 06 23:16:15 2008 -0700
@@ -849,7 +849,9 @@
          */
         public String toString() {
             return
-                "{" + argtypes + " => " + (restype == null ? "?" : restype.toString()) +
+                "{" + argtypes +
+                (restricted ? " => " : " ==> ") +
+                (restype == null ? "?" : restype.toString()) +
                 (thrown != null && thrown.nonEmpty() ? (" throws " + thrown.toString(",")) : "") +
                 "}";
         }
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Sun Jul 06 22:25:06 2008 -0700
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Sun Jul 06 23:16:15 2008 -0700
@@ -3105,7 +3105,10 @@
                 return (wt.kind == kind) ? wt.type : wt;
             }
             case TYPEVAR:
-                if (t instanceof CapturedType) {
+                // We don't eliminate "capture of ? extends" because those
+                // can result in useful conjunction types from the type
+                // parameter's bound
+                if (kind != BoundKind.EXTENDS && t instanceof CapturedType) {
                     CapturedType captured = (CapturedType) t;
                     WildcardType wt = captured.wildcard;
                     return (wt.kind == kind) ? wt.type : t;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/closures/Mahieu17.java	Sun Jul 06 23:16:15 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 test check of an inferred function type against its bound
+ * @author gafter
+ * @ignore This is likely a symptom of 6638712
+ *
+ * @clean Mahieu17
+ * @compile/fail -source 7 Mahieu17.java
+ */
+
+public class Mahieu17 {
+   public static void main(String[] args) {
+       foo() {
+           throw new Exception();
+       }
+   }
+
+   static <T extends {==> void}> void foo(T block) {
+       block.invoke();
+   }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/closures/Mahieu18.java	Sun Jul 06 23:16:15 2008 -0700
@@ -0,0 +1,10 @@
+/*
+ * @test  /nodynamiccopyright/
+ * @summary an unrestricted closure's type should be reported using the correct token
+ * @compile/fail/ref=Mahieu18.out -source 7 -XDstdout -XDrawDiagnostics Mahieu18.java
+ */
+public class Mahieu18 {
+    static <T extends {=> void}> void foo(T block) {
+        block = { ==> };
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/closures/Mahieu18.out	Sun Jul 06 23:16:15 2008 -0700
@@ -0,0 +1,2 @@
+Mahieu18.java:8:19: compiler.err.prob.found.req: (- compiler.misc.incompatible.types), { ==> void}, T
+1 error