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

Fail to substitute type when having SAM type with generics

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.18, 4.0.13
    • Static Type Checker
    • None

    Description

      I have the following program

      import java.util.*;
      
      @FunctionalInterface
      interface Foo<T> {
        int m(List<T> x);
      }
      
      class Main {
        static final void test() {
          Foo<String> p = (List<String> x) -> 1;
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.groovy: 11: [Static type checking] - Expected type java.util.List<T> for lambda parameter: x
       @ line 11, column 22.
             Foo<String> p = (List<String> x) -> 1;
                              ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Notes

      Tested against master (commit: cdc57551a7cce33ec7031b40753f25c869dcf0cc)

      Test case adapted from the following program that uses the apache-commons-collection4 lib

      
      class Main {
        static final void test() {
          org.apache.commons.collections4.sequence.ReplacementsHandler<Number> f = (int x, List<java.io.IOException> y, List<Number> z) -> { } ;
        }
      }
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: