Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11110

STC mixes names of bounded type parameters

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      import java.util.stream.*;
      
      class Main {
        static final <T extends Number>void test() {
          java.util.function.BiConsumer<T, T> func = null;
          Stream<String> stream = null;
          T res = stream.<T>collect(() -> (T) null, (T finisher, String hijacking) -> { }, func);
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.groovy: 8: [Static type checking] - Cannot assign value of type java.lang.String to variable of type T
       @ line 8, column 13.
             T res = stream.<T>collect(() -> (T) null, (T finisher, String hijacking) -> { }, func);
                     ^
      
      1 error
      
      

      Expected behavior

      Compile successfully

      Notes

      To trigger the bug, the type parameter of method test() should be bounded with name T.

      Attachments

        Activity

          People

            Unassigned Unassigned
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: