changeset 1591:d18de0997cba

Bug fixes: *) Spurious functional interface conversion error when target type inherits default methods *) 269 visitor should accept 'implicit' intersection types
author mcimadamore
date Wed, 07 Nov 2012 11:39:20 +0000
parents b38937b3090e
children dc6dec36396b
files src/share/classes/com/sun/tools/javac/code/Type.java src/share/classes/com/sun/tools/javac/code/Types.java src/share/classes/com/sun/tools/javac/comp/Attr.java test/tools/javac/lambda/TargetType47.java
diffstat 4 files changed, 60 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Type.java	Tue Nov 06 15:39:30 2012 -0800
+++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Wed Nov 07 11:39:20 2012 +0000
@@ -785,6 +785,13 @@
     
     // a clone of a ClassType that knows about the bounds of an intersection type.
     public static class IntersectionClassType extends ClassType implements IntersectionType {
+        
+        public enum IntersectionKind {
+            EXPLICIT,
+            IMPLICT;
+        }
+        
+        public IntersectionKind intersectionKind;
 
         public IntersectionClassType(List<Type> bounds, ClassSymbol csym) {
             super(Type.noType, List.<Type>nil(), csym);            
@@ -810,7 +817,9 @@
 
         @Override
         public <R, P> R accept(TypeVisitor<R, P> v, P p) {
-            return v.visitIntersection(this, p);
+            return intersectionKind == IntersectionKind.EXPLICIT ?
+                v.visitIntersection(this, p) :
+                v.visitDeclared(this, p);
         }
     }
 
--- a/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Nov 06 15:39:30 2012 -0800
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Nov 07 11:39:20 2012 +0000
@@ -400,15 +400,14 @@
             @Override
             public boolean accepts(Symbol sym) {
                     return sym.kind == Kinds.MTH &&
-                            (sym.flags() & ABSTRACT) != 0 &&
-                            (sym.flags() & DEFAULT) == 0 &&
+                            (sym.flags() & (ABSTRACT | DEFAULT)) == ABSTRACT &&
                             !overridesObjectMethod(origin, sym) &&
                             notOverridden(sym);
             }
 
             private boolean notOverridden(Symbol msym) {
                 Symbol impl = ((MethodSymbol)msym).implementation(origin, Types.this, false);
-                return impl == null || (impl.flags() & ABSTRACT) != 0;
+                return impl == null || (impl.flags() & (DEFAULT | ABSTRACT)) == ABSTRACT;
             }
         };
 
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Nov 06 15:39:30 2012 -0800
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Nov 07 11:39:20 2012 +0000
@@ -3498,7 +3498,7 @@
         }
     }
     
-    Type checkIntersection(DiagnosticPosition pos, List<JCExpression> bounds) {
+    Type checkIntersection(JCTree tree, List<JCExpression> bounds) {
         Set<Type> boundSet = new HashSet<Type>();
         if (bounds.nonEmpty()) {
             // accept class or interface or typevar as first bound.
@@ -3535,6 +3535,10 @@
             return bounds.head.type;
         } else {
             Type owntype = types.makeCompoundType(TreeInfo.types(bounds));
+            if (tree.hasTag(TYPEINTERSECTION)) {
+                ((IntersectionClassType)owntype).intersectionKind =
+                        IntersectionClassType.IntersectionKind.EXPLICIT;
+            }
             // ... the variable's bound is a class type flagged COMPOUND
             // (see comment for TypeVar.bound).
             // In this case, generate a class tree that represents the
@@ -3548,7 +3552,7 @@
                 extending = null;
                 implementing = bounds;
             }
-            JCClassDecl cd = make.at(pos).ClassDef(
+            JCClassDecl cd = make.at(tree).ClassDef(
                 make.Modifiers(PUBLIC | ABSTRACT),
                 names.empty, List.<JCTypeParameter>nil(),
                 extending, implementing, List.<JCTree>nil());
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/TargetType47.java	Wed Nov 07 11:39:20 2012 +0000
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2012, 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
+ * @summary spurious functional interface conversion errors with default methods in target type
+ * @compile TargetType47.java
+ */
+
+class TargetType47 {
+    interface A {
+        void a();
+        void b();
+        default void c() { };
+    }
+
+    interface B extends A {
+        default void b() { };
+    }
+    
+    B b = ()-> {};
+}