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

Wrong type inference in presence of a generic with bound to Double

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 11, 17, 18
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      Wrong type inference in the presence of a generic with bound to Double and use of ternary operator.
      javac rejects the following program when it should accept it.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      java Test.java

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compile
      ACTUAL -
      Test.java:7: error: incompatible types: double cannot be converted to T
          return v;
                 ^
        where T is a type-variable:
          T extends Double declared in class Test
      1 error


      ---------- BEGIN SOURCE ----------
      class Test<T extends Double, K extends T> {
        public T test() {
          T foo = (T) null;
          final var v = ((true) ?
            foo :
             (K) null);
          return v;
        }
      }

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

      FREQUENCY : always


        Attachments

          Issue Links

            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: