You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Howard (Jira)" <ji...@apache.org> on 2020/12/22 19:45:00 UTC

[jira] [Created] (GROOVY-9874) Groovy3 CompileStatic bug: extends/implements confusion

Howard created GROOVY-9874:
------------------------------

             Summary: 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


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)