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/30 16:12:00 UTC

[jira] [Resolved] (GROOVY-10327) Compiler crash when combining closure with function reference

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

Eric Milles resolved GROOVY-10327.
----------------------------------
    Resolution: Fixed

Current codebase produces this STC error, which may not be desirable.  However, the stack overflow has been addressed.

{code:groovy}
class B {
  Integer m(Integer x) { return null }
}

@groovy.transform.TypeChecked
class C<X, Y> {
  void test() {
    Closure<Integer> c = { Function<Integer,Integer> f -> 1 }
    B b = new B()
    c.call(b::m) // The argument is a method reference, but the parameter type is not a functional interface
  }
}
{code}

> Compiler crash when combining closure with function reference
> -------------------------------------------------------------
>
>                 Key: GROOVY-10327
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10327
>             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
>
> I have the following Groovy program.
> {code:groovy}
> import java.util.function.Function;
> @groovy.transform.TypeChecked
> class A<X, Y> {
>   void a() {
>     Closure<Integer> x = { Function<Integer, Integer> x -> 1};
>     B b = new B();
>     x(b::b);
>   }
> }
> class B {
>   Integer b(Integer x) { return null; }
> }
> {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:3681)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallArguments(StaticTypeCheckingVisitor.java:2794)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.inferMethodReferenceType(StaticTypeCheckingVisitor.java:3708)
> 	at org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor.visitMethodCallArguments(StaticTypeCheckingVisitor.java:2794)
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. Comment
> Tested against 4-beta-1, and master (commit: 868dabf9fadbddd13c7e8859556e4ed2796f7e1b).



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