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

STC rejects program when having SAM types and conditionals

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Static Type Checker
    • None

    Description

      I have the following program

      import java.util.function.*;
      import java.util.Deque;
      
      
      class Main {
        static final void test(Deque<Integer> p1, Supplier<Integer> p2) {
          Supplier<Integer> x = (true) ? p1::peek : p2;
          
        }
      }
      

      Actual behavior

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      test.groovy: 8: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.util.function.Supplier<java.lang.Integer>
       @ line 8, column 27.
             Supplier<Integer> x = (true) ? p1::peek : p2;
                                   ^
      
      1 error
      

      Expected behavior

      Compile successfully

      Tested against master (commit: ee93378e5c9560032284b66d33af440884c8505f)

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated: