changeset 2233:373e8f198908

8019824: very long error messages on inference error
author mcimadamore
date Wed, 03 Jul 2013 17:37:14 +0100
parents e2dd301496d6
children 2059cf03d755
files src/share/classes/com/sun/tools/javac/code/Type.java src/share/classes/com/sun/tools/javac/comp/Attr.java src/share/classes/com/sun/tools/javac/comp/Infer.java test/tools/javac/generics/inference/8019824/T8019824.java test/tools/javac/generics/inference/8019824/T8019824.out
diffstat 5 files changed, 28 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/code/Type.java	Tue Jul 02 15:46:44 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Wed Jul 03 17:37:14 2013 +0100
@@ -1379,7 +1379,7 @@
         }
         
         public void addBound(InferenceBound ib, Type bound, Types types, boolean update) {
-            Type bound2 = toTypeVarMap.apply(bound);
+            Type bound2 = boundMap.apply(bound);
             List<Type> prevBounds = bounds.get(ib);
             for (Type b : prevBounds) {
                 //check for redundancy - use strict version of isSameType on tvars
@@ -1390,12 +1390,12 @@
             notifyChange(EnumSet.of(ib));
         }
         //where
-            Type.Mapping toTypeVarMap = new Mapping("toTypeVarMap") {
+            Type.Mapping boundMap = new Mapping("toTypeVarMap") {
                 @Override
                 public Type apply(Type t) {
                     if (t.hasTag(UNDETVAR)) {
                         UndetVar uv = (UndetVar)t;
-                        return uv.qtype;
+                        return uv.inst != null ? uv.inst : uv.qtype;
                     } else {
                         return t.map(this);
                     }
--- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Jul 02 15:46:44 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Wed Jul 03 17:37:14 2013 +0100
@@ -2828,7 +2828,7 @@
             ResultInfo checkInfo =
                     resultInfo.dup(newMethodTemplate(
                         desc.getReturnType().hasTag(VOID) ? Type.noType : desc.getReturnType(),
-                        that.kind.isUnbound() ? argtypes.tail : argtypes, typeargtypes));
+                        lookupHelper.argtypes, typeargtypes));
 
             Type refType = checkId(that, lookupHelper.site, refSym, localEnv, checkInfo);
             
--- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Jul 02 15:46:44 2013 +0100
+++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Wed Jul 03 17:37:14 2013 +0100
@@ -431,6 +431,7 @@
     void checkWithinBounds(InferenceContext inferenceContext,
                              Warner warn) throws InferenceException {
         MultiUndetVarListener mlistener = new MultiUndetVarListener(inferenceContext.undetvars);
+        List<Type> saved_undet = inferenceContext.save();
         try {
             while (true) {
                 mlistener.reset();
@@ -458,6 +459,9 @@
         }
         finally {
             mlistener.detach();
+            if (mlistener.rounds == MAX_INCORPORATION_STEPS) {
+                inferenceContext.rollback(saved_undet);
+            }
         }
     }
     //where
@@ -666,7 +670,7 @@
                         if (uv2.isCaptured()) continue;
                         //alpha <: beta
                         //0. set beta :> alpha
-                        uv2.addBound(InferenceBound.LOWER, uv.qtype, infer.types);
+                        uv2.addBound(InferenceBound.LOWER, uv, infer.types);
                         //1. copy alpha's lower to beta's
                         for (Type l : uv.getBounds(InferenceBound.LOWER)) {
                             uv2.addBound(InferenceBound.LOWER, inferenceContext.asInstType(l), infer.types);
@@ -692,7 +696,7 @@
                         if (uv2.isCaptured()) continue;
                         //alpha :> beta
                         //0. set beta <: alpha
-                        uv2.addBound(InferenceBound.UPPER, uv.qtype, infer.types);
+                        uv2.addBound(InferenceBound.UPPER, uv, infer.types);
                         //1. copy alpha's upper to beta's
                         for (Type u : uv.getBounds(InferenceBound.UPPER)) {
                             uv2.addBound(InferenceBound.UPPER, inferenceContext.asInstType(u), infer.types);
@@ -718,7 +722,7 @@
                         if (uv2.isCaptured()) continue;
                         //alpha == beta
                         //0. set beta == alpha
-                        uv2.addBound(InferenceBound.EQ, uv.qtype, infer.types);
+                        uv2.addBound(InferenceBound.EQ, uv, infer.types);
                         //1. copy all alpha's bounds to beta's
                         for (InferenceBound ib : InferenceBound.values()) {
                             for (Type b2 : uv.getBounds(ib)) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/inference/8019824/T8019824.java	Wed Jul 03 17:37:14 2013 +0100
@@ -0,0 +1,15 @@
+/**
+ * @test /nodynamiccopyright/
+ * @bug 8019824
+ * @summary very long error messages on inference error
+ * @compile/fail/ref=T8019824.out -XDrawDiagnostics T8019824.java
+ */
+class T8019824 {
+    void test(Class<? extends Foo<?, ?>> cls) {
+        Foo<?, ?> foo = make(cls);
+    }
+
+    <A, B, C extends Foo<A, B>> Foo<A, B> make(Class<C> cls) { return null; }
+
+    interface Foo<A, B> {}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/generics/inference/8019824/T8019824.out	Wed Jul 03 17:37:14 2013 +0100
@@ -0,0 +1,2 @@
+T8019824.java:9:25: compiler.err.cant.apply.symbol: kindname.method, make, java.lang.Class<C>, java.lang.Class<compiler.misc.type.captureof: 1, ? extends T8019824.Foo<?,?>>, kindname.class, T8019824, (compiler.misc.incompatible.eq.upper.bounds: C, compiler.misc.type.captureof: 1, ? extends T8019824.Foo<?,?>, T8019824.Foo<java.lang.Object,B>)
+1 error