[ 
https://issues.apache.org/jira/browse/GROOVY-9890?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17346517#comment-17346517
 ] 

Paul King commented on GROOVY-9890:
-----------------------------------

The following script seems to give the expected result in the Groovy console 
with those helper classes on the classpath:
{code}
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer
import groovy.transform.CompileStatic

def config = new CompilerConfiguration()
config.addCompilationCustomizers(new ASTTransformationCustomizer(CompileStatic))

new GroovyShell(getClass().classLoader, config).evaluate('new 
groovy.bugs.groovy9890.ImplJ().foo(42L)').dump()
{code}

> Static type checking can't find default method overload on interface
> --------------------------------------------------------------------
>
>                 Key: GROOVY-9890
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9890
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 3.0.7
>         Environment: jdk 11.0.6
> dependency groovy-all 3.0.7
>            Reporter: Robin Friedli
>            Assignee: Eric Milles
>            Priority: Critical
>             Fix For: 3.0.8, 4.0.0-alpha-3
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The static type checker cannot find default methods on an interface if the 
> method overloads an abstract method. For example, consider the following Java 
> classes:
> {code:java}
> package net.robinfriedli.botify.scripting;
> public interface TestInt {
>     void foo(String s);
>     default void foo(long l) {}
> }
> public class TestImpl implements TestInt {
>     @Override
>     public void foo(String s) {
>     }
> }{code}
> When compiling the script
> {code:java}
> new net.robinfriedli.botify.scripting.TestImpl().foo(1l){code}
>  the following exception is thrown:
>  
> {code:java}
> MultipleCompilationErrorsException:
> startup failed:
> Script1.groovy: 1: [Static type checking] - Cannot find matching method 
> net.robinfriedli.botify.scripting.TestImpl#foo(long). Please check if the 
> declared type is correct and if the method exists.
>  @ line 1, column 1.
>    new net.robinfriedli.botify.scripting.TestImpl().foo(1l)
>    ^
> 1 error
> {code}
> The script runs fine without static compilation.
>  
> Calling the implemented abstract method compiles sucessfully:
> {code:java}
> new net.robinfriedli.botify.scripting.TestImpl().foo('str')
> {code}
> However, when changing the interface to
>  
> {code:java}
> package net.robinfriedli.botify.scripting;
> public interface TestInt {
>     void foo(String s);
>     default void bar(long l) {}
> }
> {code}
> The following script compiles:
>  
>  
> {code:java}
> new net.robinfriedli.botify.scripting.TestImpl().bar(1l)
> {code}
>  
> The scripts are executed in Java by GroovyShell#evaluate using the following 
> compiler configuration:
> {code:java}
> CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
> ASTTransformationCustomizer compileStaticCustomizer = new 
> ASTTransformationCustomizer(
>     singletonMap("extensions", 
> singletonList("net.robinfriedli.botify.scripting.TypeCheckingExtension")),
>     CompileStatic.class
> );
> compilerConfiguration.addCompilationCustomizers(compileStaticCustomizer);
> return compilerConfiguration;
> {code}
>  



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

Reply via email to