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

SAM types not working well along with overloading

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Information Provided
    • None
    • None
    • Static Type Checker

    Description

      I have the following program:

      import java.util.*;
      import java.util.function.*;
      
      class Bar {
        LinkedList<String> collect(Supplier<String> function) { }
              List<String> collect(String x, int y, int z) { }
      }
      
      class Main {
        static final void test() {
          Bar x = null;
          LinkedList<String> d = x.collect(() -> "fda");
        }
      }
      

      Actual behaviour

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 14: [Static type checking] - Cannot assign value of type java.util.List<java.lang.String> to variable of type java.util.LinkedList<java.lang.String>
       @ line 14, column 28.
             LinkedList<String> d = x.collect(() -> "fda");
                                    ^
      
      1 error
      

      Expected behaviour

      Compile successfully

      Notes

      Tested against master (commit: cac91791764b8f0b3338318248474412f89e3456)

      Adapted from:

      import java.util.*;
      import java.util.function.*;
      
      import org.eclipse.collections.api.tuple.primitive.BooleanBooleanPair;
      import org.eclipse.collections.api.map.primitive.*;
      import org.eclipse.collections.api.factory.map.primitive.*;
      import org.eclipse.collections.api.collection.*;
      import org.eclipse.collections.api.factory.map.primitive.MutableDoubleFloatMapFactory;
      
      class Main {
        static final <G, W>void test() {
          ImmutableObjectDoubleMap<LongFunction<BooleanBooleanPair>> d = null;
          final ImmutableCollection<MutableDoubleFloatMapFactory> x = d.collect((p) -> (MutableDoubleFloatMapFactory) null );
        }
      }
      

      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: