You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2020/12/23 01:50:00 UTC
[jira] [Commented] (GROOVY-9874) Groovy3 CompileStatic bug:
extends/implements confusion
[ https://issues.apache.org/jira/browse/GROOVY-9874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17253836#comment-17253836 ]
Paul King commented on GROOVY-9874:
-----------------------------------
Your example ran fine for me with Groovy 3.0.7. The error message you are getting hints that you have another {{Abc}} class with an inner {{Def}} class also on your classpath?
> Groovy3 CompileStatic bug: extends/implements confusion
> -------------------------------------------------------
>
> Key: GROOVY-9874
> URL: https://issues.apache.org/jira/browse/GROOVY-9874
> Project: Groovy
> Issue Type: Bug
> Reporter: Howard
> Priority: Major
>
> The following code compiles on groovy 2 but does not compile on groovy 3
> {code:java}
> import groovy.transform.CompileStatic
> @CompileStatic
> public class Abc implements Def {
> private double[] myabc;
>
> Abc(){
> myabc = new double[1];
> }
> public Def clone() {
> Abc a = (Abc) super.clone();
> a.myabc = myabc.clone() as double[]
> return a
> }
> }
> public interface Def extends Cloneable {
> public Def clone() throws CloneNotSupportedException;
> }
> new Abc().clone()
> {code}
> groovy3 error msg
> {code:java}
> [Static type checking] - Cannot return value of type Abc on method returning type Abc$Def
> at line: 14, column: 16
> {code}
> however when i comment out the CompileStatic annotation, i get
> {code:java}
> You are not allowed to implement the class 'Abc$Def', use extends instead.
> at line: 4, column: 1
> {code}
> which is odd because Def is an interface. And when I did change it to extends, i get
> {code:java}
> java.lang.NoSuchMethodError: Abc$Def: method 'void <init>()' not found
> at Abc.<init>(ConsoleScript141)
> at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
> at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> at ConsoleScript141.run(ConsoleScript141:23)
> {code}
> which is not expected given that the interface cannot have a constructor.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)