Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
3.0.7
-
None
Description
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:
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) { } }
When compiling the script
new net.robinfriedli.botify.scripting.TestImpl().foo(1l)
the following exception is thrown:
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
The script runs fine without static compilation.
Calling the implemented abstract method compiles sucessfully:
new net.robinfriedli.botify.scripting.TestImpl().foo('str')
However, when changing the interface to
package net.robinfriedli.botify.scripting; public interface TestInt { void foo(String s); default void bar(long l) {} }
The following script compiles:
new net.robinfriedli.botify.scripting.TestImpl().bar(1l)
The scripts are executed in Java by GroovyShell#evaluate using the following compiler configuration:
CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); ASTTransformationCustomizer compileStaticCustomizer = new ASTTransformationCustomizer( singletonMap("extensions", singletonList("net.robinfriedli.botify.scripting.TypeCheckingExtension")), CompileStatic.class ); compilerConfiguration.addCompilationCustomizers(compileStaticCustomizer); return compilerConfiguration;
Attachments
Issue Links
- relates to
-
GROOVY-10700 STC cannot locate method specified by interface but supplied by AST transform
- Closed