Failure to detect conflicting upper bounds in inference

XMLWordPrintable

      Test:

      ---
      import java.util.List;

      public class GLBConflict {

          interface I<S> {}
          interface J<S> extends I<S> {}
          interface J2<S> extends I<S> {}
          interface K extends I<String> {}

          <T> T upper2(List<? super T> l1, List<? super T> l2) { return null; }

          void test(List<I<String>> i, List<J<Integer>> j, List<J2<String>> j2, List<K> k) {
              upper2(i, j); // expected: error; actual: error
              upper2(j, j2); // expected: error; actual: ok
              upper2(j, k); // expected: error; actual: ok
          }

      }
      ---

      All three invocations of 'upper2' should fail, due to this clause (JLS 8 18.3):

      "If two bounds have the form α <: S and α <: T, and if for some generic class or interface, G, there exists a supertype (4.10) of S of the form G<S1, ..., Sn> and a supertype of T of the form G<T1, ..., Tn>, then for all i, 1 ≤ i ≤ n, if Si and Ti are types (not wildcards), the constraint ⟨Si = Ti⟩ is implied."

      Under '-source 7' and previous, there is not a clear specification for an error, but all three invocations otherwise produce a malformed intersection, which javac makes some effort to prevent. If the first one is an error (javac claims it is), the other two should be errors, too.

            Assignee:
            Vicente Arturo Romero Zaldivar
            Reporter:
            Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: