Richard Warburton | 17 Jun 2012 12:16
Picon
Gravatar

[groovy-dev] Type Checking Bug around static methods

Again this is using Groovy 2, rc-3.  Minimal example program:

import groovy.transform.TypeChecked
import java.util.Arrays

 <at> TypeChecked
class ArrayCopying {

    public static void main(String[] args) {
        def acopy = Arrays.copyOf(args, 1)
    }

}

-----------------------------------------

I get the following error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
ArrayCopying.groovy: 9: [Static type checking] - Cannot find matching
method java.lang.Class#copyOf([Ljava.lang.String;, int)
  <at>  line 9, column 21.
           def acopy = Arrays.copyOf(args, 1)
                       ^

1 error

Now if I remove the  <at> TypeChecked annotation, it not only compiles, but
executes without error.  It seems like the type checker hasn't figured
out that I'm trying to invoke the static method copyOf from the class
(Continue reading)

Paul King | 17 Jun 2012 13:09
Picon
Favicon
Gravatar

Re: [groovy-dev] Type Checking Bug around static methods


Looks like a bug to me. Please file an issue.

Cheers, Paul.

On 17/06/2012 8:16 PM, Richard Warburton wrote:
> Again this is using Groovy 2, rc-3.  Minimal example program:
>
> import groovy.transform.TypeChecked
> import java.util.Arrays
>
>  <at> TypeChecked
> class ArrayCopying {
>
>      public static void main(String[] args) {
>          def acopy = Arrays.copyOf(args, 1)
>      }
>
> }
>
> -----------------------------------------
>
> I get the following error:
>
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> ArrayCopying.groovy: 9: [Static type checking] - Cannot find matching
> method java.lang.Class#copyOf([Ljava.lang.String;, int)
>    <at>  line 9, column 21.
>             def acopy = Arrays.copyOf(args, 1)
>                         ^
(Continue reading)

Cédric Champeau | 18 Jun 2012 16:20
Picon
Gravatar

Re: [groovy-dev] Type Checking Bug around static methods

Created for reference: http://jira.codehaus.org/browse/GROOVY-5525

Le 17/06/2012 13:09, Paul King a écrit :

Looks like a bug to me. Please file an issue.

Cheers, Paul.

On 17/06/2012 8:16 PM, Richard Warburton wrote:
Again this is using Groovy 2, rc-3.  Minimal example program:

import groovy.transform.TypeChecked
import java.util.Arrays

<at> TypeChecked
class ArrayCopying {

     public static void main(String[] args) {
         def acopy = Arrays.copyOf(args, 1)
     }

}

-----------------------------------------

I get the following error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
ArrayCopying.groovy: 9: [Static type checking] - Cannot find matching
method java.lang.Class#copyOf([Ljava.lang.String;, int)
  <at> line 9, column 21.
            def acopy = Arrays.copyOf(args, 1)
                        ^

1 error

Now if I remove the <at> TypeChecked annotation, it not only compiles, but
executes without error.  It seems like the type checker hasn't figured
out that I'm trying to invoke the static method copyOf from the class
java.util.Arrays, rather than a copyOf method on an instance of
java.lang.Class called Arrays.

Can someone point me in the direction of the typing rules for groovy,
so I can be a little more sure that I'm not just writing mistyped
programs.  I did have a look on the wiki, but didn't see them.

regards,

   Richard

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

     http://xircles.codehaus.org/manage_email





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





-- Cédric Champeau SpringSource - A Division Of VMware http://www.springsource.com/ http://twitter.com/CedricChampeau

Gmane