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

STC chooses to call a non-polymorphic method although explicit type arguments are given

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • None
    • None
    • Static Type Checker

    Description

      I have the following code:

      import java.util.concurrent.*;
      
      class Main {
        static final void test() {
          ExecutorService z = null;
          Future<CharSequence> future = z.<CharSequence>submit(() -> "fd");
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Main.groovy: 7: [Static type checking] - Incompatible generic argument types. Cannot assign java.util.concurrent.Future<? extends java.lang.Object> to: java.util.concurrent.Future<java.lang.CharSequence>
       @ line 7, column 35.
             Future<CharSequence> future = z.<CharSequence>submit(() -> "fd");
                                           ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Notes

      It seems that the compiler chooses to call the variant that takes no type arguments (see https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/ExecutorService.html#submit(java.lang.Runnable), even though explicit type arguments are given.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: