Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5021635

Incorrect default inferred type parameter when type params interdependent

    Details

    • Subcomponent:
    • Resolved In Build:
      b03
    • CPU:
      generic, x86
    • OS:
      solaris_8, windows_xp
    • Verification:
      Verified

      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).

        Attachments

          Activity

            People

            • Assignee:
              ahe Peter Ahe
              Reporter:
              gafter Neal Gafter
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: