changeset 1830:5868b9c53cfd

Bug fixes: 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply 8005183: Missing accessor for constructor reference pointing to private inner class ctor 8008293: Declared bounds not considered when functional interface containing unbound wildcards is instantiated
author mcimadamore
date Fri, 15 Feb 2013 14:57:08 +0000
parents dae2aede7f35
children a2b6e71c5b62
files src/share/classes/com/sun/tools/javac/code/Types.java src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java test/tools/javac/lambda/MethodReference63.java test/tools/javac/lambda/TargetType64.java test/tools/javac/lambda/speculative/MissingError.java test/tools/javac/lambda/speculative/MissingError.out
diffstat 8 files changed, 142 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Feb 14 17:28:59 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Fri Feb 15 14:57:08 2013 +0000
@@ -579,7 +579,17 @@
             for (Type t : formalInterface.getTypeArguments()) {
                 if (actualTypeargs.head.hasTag(WILDCARD)) {
                     WildcardType wt = (WildcardType)actualTypeargs.head;
-                    typeargs.append(wt.type);
+                    Type bound;
+                    switch (wt.kind) {
+                        case UNBOUND:
+                            //use declared bound if it doesn't depend on formal type-args
+                            bound = wt.bound.bound.containsAny(formalInterface.getTypeArguments()) ?
+                                    syms.objectType : wt.bound.bound;
+                            break;
+                        default:
+                            bound = wt.type;
+                    }
+                    typeargs.append(bound);
                 } else {
                     typeargs.append(actualTypeargs.head);
                 }
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Feb 14 17:28:59 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Fri Feb 15 14:57:08 2013 +0000
@@ -276,14 +276,27 @@
      * disabled during speculative type-checking.
      */
     JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
-        JCTree newTree = new TreeCopier<Object>(make).copy(tree);
+        final JCTree newTree = new TreeCopier<Object>(make).copy(tree);
         Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared()));
         speculativeEnv.info.scope.owner = env.info.scope.owner;
-        final JavaFileObject currentSource = log.currentSourceFile();
         Log.DeferredDiagnosticHandler deferredDiagnosticHandler =
                 new Log.DeferredDiagnosticHandler(log, new Filter<JCDiagnostic>() {
-            public boolean accepts(JCDiagnostic t) {
-                return t.getDiagnosticSource().getFile().equals(currentSource);
+            public boolean accepts(final JCDiagnostic t) {
+                class PosScanner extends TreeScanner {
+                    boolean found = false;
+                    
+                    @Override
+                    public void scan(JCTree tree) {
+                        if (tree != null &&
+                                tree.pos() == t.getDiagnosticPosition()) {
+                            found = true;
+                        }
+                        super.scan(tree);
+                    }
+                };
+                PosScanner posScanner = new PosScanner();
+                posScanner.scan(newTree);
+                return posScanner.found;
             }
         });
         try {
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Feb 14 17:28:59 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Fri Feb 15 14:57:08 2013 +0000
@@ -1726,13 +1726,18 @@
             boolean isArrayOp() {
                 return tree.sym.owner == syms.arrayClass;
             }
+            
+            boolean isPrivateConstructor() {
+                return tree.sym.name == names.init &&
+                        (tree.sym.flags() & PRIVATE) != 0;
+            }
 
             /**
              * Does this reference needs a bridge (i.e. var args need to be
              * expanded or "super" is used)
              */
             final boolean needsBridge() {
-                return isSuper || needsVarArgsConversion() || isArrayOp();
+                return isSuper || needsVarArgsConversion() || isArrayOp() || isPrivateConstructor();
             }
 
             Type generatedRefSig() {
--- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Thu Feb 14 17:28:59 2013 +0000
+++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Fri Feb 15 14:57:08 2013 +0000
@@ -483,6 +483,10 @@
     public long getEndPosition() {
         return getIntEndPosition();
     }
+    
+    public DiagnosticPosition getDiagnosticPosition() {
+        return position;
+    }
 
     /**
      * Get the line number within the source referred to by this diagnostic.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/MethodReference63.java	Fri Feb 15 14:57:08 2013 +0000
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 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.
+ */
+
+/*
+ * @test
+ * @bug 8005183
+ * @summary Missing accessor for constructor reference pointing to private inner class ctor
+ */
+public class MethodReference63 {
+    
+    interface SAM {
+        void m();
+    }
+    
+    static class Foo {
+        private Foo() { }    
+    }
+
+    public static void main(String[] args) {
+        SAM s = Foo::new;
+        s.m();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/TargetType64.java	Fri Feb 15 14:57:08 2013 +0000
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 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.
+ */
+
+/*
+ * @test
+ * @bug 8008293
+ * @summary Declared bounds not considered when functional interface containing unbound wildcards is instantiated
+ * @compile TargetType64.java
+ */
+class TargetType64 {
+    interface SAM<X extends Number> {
+        void m(X x);
+    }
+    
+    void g(Object o) { }
+
+    void test() {
+        SAM<?> s1 = (x)->{};
+        SAM<?> s2 = this::g;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/speculative/MissingError.java	Fri Feb 15 14:57:08 2013 +0000
@@ -0,0 +1,17 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8008276
+ * @summary assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
+ * @compile/fail/ref=MissingError.out -XDrawDiagnostics MissingError.java
+ */
+class MissingError { 
+    void test() { 
+       mtest(new Bad(){ Integer i = ""; });
+    } 
+
+    void mtest(Bad t){ }
+}
+
+class Bad {
+    String s = 1;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/speculative/MissingError.out	Fri Feb 15 14:57:08 2013 +0000
@@ -0,0 +1,3 @@
+MissingError.java:16:16: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: int, java.lang.String)
+MissingError.java:9:37: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: java.lang.String, java.lang.Integer)
+2 errors