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

Type inference bug related to bound computation of intersection types

    Details

    • Subcomponent:
    • Introduced In Build:
      b24
    • Introduced In Version:
      12
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Recent macOS, JDK 12.

      A DESCRIPTION OF THE PROBLEM :
      I use generics to compute the upper bound type of generic varags parameters. Prior to JDK 12 the attached example compiled fine. Starting with JDK 12, javac shows errors.

      REGRESSION : Last worked in version 11.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Copy the attached source code into a file BoundTest.java
      2. javac BoundTest.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The example does compile without errors.
      ACTUAL -
      The compiler outputs the following error message:

      BoundTest.java:4: error: incompatible types: cannot infer type-variable(s) T,R
              Number zero = a(
                             ^
          (argument mismatch; bad return type in lambda expression
            BigDecimal cannot be converted to INT#1)
        where T,R are type-variables:
          T extends Object declared in method <T,R>c(Function<T,R>)
          R extends Object declared in method <T,R>c(Function<T,R>)
        where INT#1,INT#2 are intersection types:
          INT#1 extends Number,Comparable<? extends INT#2>,Constable,ConstantDesc
          INT#2 extends Number,Comparable<?>,Constable,ConstantDesc
      1 error


      ---------- BEGIN SOURCE ----------
      interface BoundTest {

          default void shouldCompile() {
              Number zero = a(
                      b(0),
                      b(0.0),
                      c(ignored -> java.math.BigDecimal.ZERO)
              );
          }

          <R> X<R> b(R r);

          <T, R> X<R> c(java.util.function.Function<T, R> f);

          @SafeVarargs
          static <R> R a(X<R>... xs) { return null; }

          interface X<R> {}

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              vromero Vicente Arturo Romero Zaldivar
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: