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

Type checking fails when casting method references

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      Probably related to GROOVY-10270.

      I have the following program

      import java.util.function.*;
      import java.util.stream.*;
      
      
      class Main {
        static final void test() {
          Foo<Object, String> x = null;
          Foo<String, String> y = null;
          BinaryOperator<String> z = null;
      
          final Object powdery = java.util.stream.Collectors.toConcurrentMap(
              x::m as Function<Object, String>,
              y::m as Function<String, String>,
              z
          );
        }
      }
      
      interface Foo<T1, T2> {
        T2 m(T1 x);
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 11: [Static type checking] - Cannot call <T,K,U> java.util.stream.Collectors#toConcurrentMap(java.util.function.Function<? super T, ? extends K>, java.util.function.Function<? super T, ? extends U>, java.util.function.BinaryOperator<U>) with arguments [java.util.function.Function<java.lang.Object, java.lang.String>, java.util.function.Function<java.lang.String, java.lang.String>, java.util.function.BinaryOperator<java.lang.String>]
       @ line 11, column 28.
             final Object powdery = java.util.stream.Collectors.toConcurrentMap(
                                    ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      Notes: If a remove type casts, the code compiles as expected.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: