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

STC: Stackoverflow Error when passing function reference to closure

    XMLWordPrintableJSON

Details

    Description

      I have the following Groovy program.

      import java.util.function.Consumer;
      
      @groovy.transform.TypeChecked
      class Test {
        static final void foo(Integer y) {}
      
        static final void bar(Consumer<Integer> x) {}
      
        public static void main () {
          def qux = { Consumer<Integer> x -> }
          Test.bar(Test::foo) // OK
          qux(Test::foo) // Crashes
        }
      }
      

      Actual Behavior

      The compiler crashes with the following stacktrace.

      >>> a serious error occurred: null
      >>> stacktrace:
      java.lang.StackOverflowError
      	at java.base/java.util.stream.MatchOps$1MatchSink.accept(MatchOps.java:90)
      	at java.base/java.util.LinkedList$LLSpliterator.tryAdvance(LinkedList.java:1253)
      	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
      	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
      	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
      	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
      	at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
      	at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
      	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      	at java.base/java.util.stream.ReferencePipeline.noneMatch(ReferencePipeline.java:538)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferMethodReferenceType(StaticTypeCheckingVisitor.java:3653)
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallArguments(StaticTypeCheckingVisitor.java:2814)
          ...
      	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallArguments(StaticTypeCheckingVisitor.java:2814)
      

      Expected Behavior

      Compile successfully.

      Comment

      The program compiles with 4.0.0-alpha-x with the following error; thus, it does not crash the compiler. It crashes the compiler in 4.0.0-beta-1 and master (commit: 9a642c928fbf5dc430dbe2c67357a26033b12c55).

      Test.groovy: 12: The argument is a method reference, but the parameter type is not a functional interface
       @ line 12, column 9.
             qux(Test::foo) // Crashes
                 ^
      
      1 error
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              schaliasos Stefanos Chaliasos
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: