langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java
changeset 8044 7fd529d4472c
parent 8036 17b976649c61
child 8048 25caac41b294
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java	Wed Jan 19 19:01:35 2011 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java	Mon Jan 24 15:44:15 2011 +0000
@@ -205,19 +205,20 @@
      *  Throw a NoInstanceException if this not possible.
      */
     void maximizeInst(UndetVar that, Warner warn) throws NoInstanceException {
+        List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
         if (that.inst == null) {
-            if (that.hibounds.isEmpty())
+            if (hibounds.isEmpty())
                 that.inst = syms.objectType;
-            else if (that.hibounds.tail.isEmpty())
-                that.inst = that.hibounds.head;
+            else if (hibounds.tail.isEmpty())
+                that.inst = hibounds.head;
             else
-                that.inst = types.glb(that.hibounds);
+                that.inst = types.glb(hibounds);
         }
         if (that.inst == null ||
             that.inst.isErroneous())
             throw ambiguousNoInstanceException
                 .setMessage("no.unique.maximal.instance.exists",
-                            that.qtype, that.hibounds);
+                            that.qtype, hibounds);
     }
     //where
         private boolean isSubClass(Type t, final List<Type> ts) {
@@ -241,37 +242,46 @@
             return true;
         }
 
+    private Filter<Type> errorFilter = new Filter<Type>() {
+        @Override
+        public boolean accepts(Type t) {
+            return !t.isErroneous();
+        }
+    };
+
     /** Instantiate undetermined type variable to the lub of all its lower bounds.
      *  Throw a NoInstanceException if this not possible.
      */
     void minimizeInst(UndetVar that, Warner warn) throws NoInstanceException {
+        List<Type> lobounds = Type.filter(that.lobounds, errorFilter);
         if (that.inst == null) {
-            if (that.lobounds.isEmpty())
+            if (lobounds.isEmpty())
                 that.inst = syms.botType;
-            else if (that.lobounds.tail.isEmpty())
-                that.inst = that.lobounds.head.isPrimitive() ? syms.errType : that.lobounds.head;
+            else if (lobounds.tail.isEmpty())
+                that.inst = lobounds.head.isPrimitive() ? syms.errType : lobounds.head;
             else {
-                that.inst = types.lub(that.lobounds);
+                that.inst = types.lub(lobounds);
             }
             if (that.inst == null || that.inst.tag == ERROR)
                     throw ambiguousNoInstanceException
                         .setMessage("no.unique.minimal.instance.exists",
-                                    that.qtype, that.lobounds);
+                                    that.qtype, lobounds);
             // VGJ: sort of inlined maximizeInst() below.  Adding
             // bounds can cause lobounds that are above hibounds.
-            if (that.hibounds.isEmpty())
+            List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
+            if (hibounds.isEmpty())
                 return;
             Type hb = null;
-            if (that.hibounds.tail.isEmpty())
-                hb = that.hibounds.head;
-            else for (List<Type> bs = that.hibounds;
+            if (hibounds.tail.isEmpty())
+                hb = hibounds.head;
+            else for (List<Type> bs = hibounds;
                       bs.nonEmpty() && hb == null;
                       bs = bs.tail) {
-                if (isSubClass(bs.head, that.hibounds))
+                if (isSubClass(bs.head, hibounds))
                     hb = types.fromUnknownFun.apply(bs.head);
             }
             if (hb == null ||
-                !types.isSubtypeUnchecked(hb, that.hibounds, warn) ||
+                !types.isSubtypeUnchecked(hb, hibounds, warn) ||
                 !types.isSubtypeUnchecked(that.inst, hb, warn))
                 throw ambiguousNoInstanceException;
         }
@@ -528,7 +538,8 @@
         for (List<Type> tvs = tvars, args = arguments;
              tvs.nonEmpty();
              tvs = tvs.tail, args = args.tail) {
-            if (args.head instanceof UndetVar) continue;
+            if (args.head instanceof UndetVar ||
+                    tvars.head.getUpperBound().isErroneous()) continue;
             List<Type> bounds = types.subst(types.getBounds((TypeVar)tvs.head), tvars, arguments);
             if (!types.isSubtypeUnchecked(args.head, bounds, warn))
                 throw invalidInstanceException