You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/10/12 21:21:00 UTC

[jira] [Updated] (GROOVY-10269) STC: Stackoverflow Error when passing function reference to closure

     [ https://issues.apache.org/jira/browse/GROOVY-10269?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles updated GROOVY-10269:
---------------------------------
    Fix Version/s: 3.0.10

> STC: Stackoverflow Error when passing function reference to closure
> -------------------------------------------------------------------
>
>                 Key: GROOVY-10269
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10269
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 4.0.0-beta-1
>            Reporter: Stefanos Chaliasos
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-2, 3.0.10
>
>
> I have the following Groovy program.
> {code:groovy}
> 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
>   }
> }
> {code}
> h2. Actual Behavior
> The compiler crashes with the following stacktrace.
> {code:java}
> >>> 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)
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. 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).
> {code:java}
> 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
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)