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

skip type inference for non functional interface components of intersection types

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 11
    • 11
    • tools
    • b15
    • Verified

        After the fix for JDK-8148354 was pushed we found that the following code based in a JCK test started failing:

        class U1 {}
        class U2 {}
        class U3 {}

        interface SAM<P1 extends U1, P2 extends U2, P3 extends U3> {
            P3 m(P1 p1, P2 p2);
        }

        interface I<T> {}

        @SuppressWarnings("unchecked")
        class Tester {
            Object method(SAM<U1, U2, U3> sam) {
                return null;
            }

            Object run() {
                return method((SAM<U1, U2, U3> & I<?>) (U1 u1, U2 u2) -> { return new U3(); });
            }
        }

        The reason is that `I` is not a functional interface. As the proposal to fix JDK-8148354 implies splitting the intersection into its components, doing type inference and remove wildcards on those components and build a new intersection type from them. We realized that there is no point on doing type inference on an interface that is not a functional interface so it has no chance of adding any constraints to the target type to be obtained. So we propose to skip type inference on components of an intersection type which are not a functional interface.

              vromero Vicente Arturo Romero Zaldivar
              vromero Vicente Arturo Romero Zaldivar
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: