United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-5021635 Incorrect default inferred type parameter when type params interdependent
JDK-5021635 : Incorrect default inferred type parameter when type params interdependent

Details
Type:
Bug
Submit Date:
2004-03-26
Status:
Closed
Updated Date:
2010-07-09
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
tools
OS:
solaris_8,windows_xp
Sub-Component:
javac
CPU:
x86,generic
Priority:
P5
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports

Sub Tasks

Description
I'm trying to understand the compiler behavior in this case:

  class M<T> {}
  class Main {
    static <T extends M<U>, U> void f1() {
    }
    void g(M m1) {
        f1();
    }
  }

when I compile this I get

H.java:6: incompatible types; inferred type argument(s) M<U>,java.lang.Object do not conform to bounds of type variable(s) T,U
found   : <T,U>void
required: void
        f1();
          ^

This doesn't make sense.  Why didn't it infer M<Object>,Object?  What is this 'U' that appears in the argument to M in the error message?  Is there a type substitution missing somewhere in the compiler?

Strangely, it still fails if I change the order of the formal type parameters, but with a different message altogether.

I think the compiler has to be able to handle this kind of code in order to be able to handle calls involving raw types (in the new overload resolution algorithm, raw types underconstrain the type parameters).

                                    

Comments
EVALUATION

It looks like there is indeed a substitution missing, maybe because of
the order that things get applied. I'll investigate.

###@###.### 2004-03-29
                                     
2004-03-29
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
dragon
mustang


                                     
2004-09-07
SUGGESTED FIX

Index: j2se/src/share/classes/com/sun/tools/javac/comp/Infer.java
--- /tmp/geta3925	2006-10-31 23:02:19.000000000 -0800
+++ /tmp/getb3925	2006-10-31 23:02:19.000000000 -0800
@@ -244,6 +244,7 @@
 
         // check bounds
         List<Type> targs = Type.map(undetvars, getInstFun);
+        targs = types.subst(targs, that.tvars, targs);
         checkWithinBounds(that.tvars, targs, warn);
 
         return getInstFun.apply(qtype1);
                                     
2006-11-01
EVALUATION

Indeed.  The type inferred for the type variables could still refer to
the type variables.
                                     
2006-11-01
SUGGESTED FIX

Webrev of changes: http://sa.sfbay/projects/langtools/bugid_summary.pl?bugid=5021635
See also attachment 5021635.tar.gz.
                                     
2006-11-01



Hardware and Software, Engineered to Work Together