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

javac bounds scope incorrectly for multiple inlined methods/operations

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      This bug is present in JDK 8, 9, 10 and 11-EA releases. The bug is present on both windows and linux platforms.

      A DESCRIPTION OF THE PROBLEM :
      Consider the attached single class. There should be a compiler error at the line FirstClass.create(transformer.valueOf(true)).toNextClass(); , however javac compiles this code fine.
      The compiler error should be that Incompatible types are returned: expected <V> actual <? extends V> .
      IntelliJ and Eclipse both show this error correctly, but javac compiles fine

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Consider the class below, there should be a compiler error at the commented line. javac should not infer the upper bounds and replace it with <V>
      public class BugReport {

          public static class FirstClass<T> {

              public static <E> FirstClass<E> create(E... elements) {
                  return new FirstClass<>();
              }

              public NextClass<T> toNextClass() {
                  return new NextClass<>();
              }
          }

          public static class NextClass<T> {

              public NextClass() {

              }
          }

          public interface Transformer<V> {

              V valueOf(boolean parameter);
          }

          public class TestImpl {

              public <V> NextClass<V> test(Transformer<? extends V> transformer) {
                  return FirstClass.create(transformer.valueOf(true)).toNextClass(); // There should be a compiler error on this line.
              }
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      there should be a compiler error at the commented line. javac should not infer the upper bounds and replace it with <V>
      ACTUAL -
      javac compiles fine

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: