Discussion:
[groovy-dev] MissingMethodException: Generic methods and arrays
Thibault Kruse
2015-03-02 14:32:20 UTC
Permalink
Hi,

using groovy 2.4.1 (and earlier), I faced several weird / invalid
errors, some related to IntelliJ, some in Groovy.

At least this one seems to be by Groovy:

class TestGenerics {
static <T> List<T> randomSample(T[] sequence, String a) {
return Arrays.asList(sequence)[0..1]
}
static void main(String[] args) {
List val = randomSample([1, 2, 3] as int[], '1')
}
}

kruset:/tmp $ groovy TestGenerics.groovy
Caught: groovy.lang.MissingMethodException: No signature of method:
static TestGenerics.randomSample() is applicable for argument types:
([I, java.lang.String) values: [[1, 2, 3], 1]

If I remove the superfluous String argument, it works fine.

Sadly the IntelliJ groovy parser seems to be independent of the used
groovyc version, so the visible editor output does not always match
what a given groovyc version will accept.

Should I open a JIRA ticket?

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

http://xircles.codehaus.org/manage_email
Thibault Kruse
2015-03-02 14:54:57 UTC
Permalink
Also, maybe related, type checking related to Java Enum values() seems bad:

import groovy.transform.TypeChecked

import java.nio.file.StandardCopyOption

enum TestEnum {
A, B, C
}

@TypeChecked
class TestGenerics {
public static <T> List<T> randomSample(T[] sequence) {
return Arrays.asList(sequence)[0..1]
}

def test1 = randomSample(TestEnum.values())
def test2 = randomSample(StandardCopyOption.values())
}

/tmp/TestGenerics.groovy: 16: [Static type checking] - Cannot call <T>
TestGenerics#randomSample(T[]) with arguments
[java.nio.file.StandardCopyOption[]]
@ line 16, column 17.
def test2 = randomSample(StandardCopyOption.values())


TypeChecker fails for declaration of test2, but not of test1.

I would guess this is a separate JIRA issue.
Post by Thibault Kruse
Hi,
using groovy 2.4.1 (and earlier), I faced several weird / invalid
errors, some related to IntelliJ, some in Groovy.
class TestGenerics {
static <T> List<T> randomSample(T[] sequence, String a) {
return Arrays.asList(sequence)[0..1]
}
static void main(String[] args) {
List val = randomSample([1, 2, 3] as int[], '1')
}
}
kruset:/tmp $ groovy TestGenerics.groovy
([I, java.lang.String) values: [[1, 2, 3], 1]
If I remove the superfluous String argument, it works fine.
Sadly the IntelliJ groovy parser seems to be independent of the used
groovyc version, so the visible editor output does not always match
what a given groovyc version will accept.
Should I open a JIRA ticket?
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Jochen Theodorou
2015-03-02 15:26:45 UTC
Permalink
Post by Thibault Kruse
Hi,
using groovy 2.4.1 (and earlier), I faced several weird / invalid
errors, some related to IntelliJ, some in Groovy.
class TestGenerics {
static <T> List<T> randomSample(T[] sequence, String a) {
return Arrays.asList(sequence)[0..1]
}
static void main(String[] args) {
List val = randomSample([1, 2, 3] as int[], '1')
}
}
kruset:/tmp $ groovy TestGenerics.groovy
([I, java.lang.String) values: [[1, 2, 3], 1]
If I remove the superfluous String argument, it works fine.
That is because without the String parameter you are doing a "variable
argument" call. Unlike Java in Groovy it is enough to just use an array.
But it needs to be the last parameter. btw, in your case T[] won't be
[1,2,3], but [[1,2,3]]. In other words an Object[] with a single
element, which is an int[]
Post by Thibault Kruse
Sadly the IntelliJ groovy parser seems to be independent of the used
groovyc version, so the visible editor output does not always match
what a given groovyc version will accept.
Should I open a JIRA ticket?
If intellij does not accept the String-less version, then it is a bug.
The case is no different from Java if T... had been used. But of course
that would go in the intellij JIRA, not ours then. Unless I
misunderstand you of course

bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org


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

http://xircles.codehaus.org/manage_email
Thibault Kruse
2015-03-02 15:37:17 UTC
Permalink
Ah, I see. And also I was confused over the primitive int[] arrays not
being acceptable by a method with a generic array parameter.
Post by Jochen Theodorou
Post by Thibault Kruse
Hi,
using groovy 2.4.1 (and earlier), I faced several weird / invalid
errors, some related to IntelliJ, some in Groovy.
class TestGenerics {
static <T> List<T> randomSample(T[] sequence, String a) {
return Arrays.asList(sequence)[0..1]
}
static void main(String[] args) {
List val = randomSample([1, 2, 3] as int[], '1')
}
}
kruset:/tmp $ groovy TestGenerics.groovy
([I, java.lang.String) values: [[1, 2, 3], 1]
If I remove the superfluous String argument, it works fine.
That is because without the String parameter you are doing a "variable
argument" call. Unlike Java in Groovy it is enough to just use an array. But
it needs to be the last parameter. btw, in your case T[] won't be [1,2,3],
but [[1,2,3]]. In other words an Object[] with a single element, which is an
int[]
Post by Thibault Kruse
Sadly the IntelliJ groovy parser seems to be independent of the used
groovyc version, so the visible editor output does not always match
what a given groovyc version will accept.
Should I open a JIRA ticket?
If intellij does not accept the String-less version, then it is a bug. The
case is no different from Java if T... had been used. But of course that
would go in the intellij JIRA, not ours then. Unless I misunderstand you of
course
bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Thibault Kruse
2015-03-02 15:38:22 UTC
Permalink
Still the second problem with the Java enum vs. Groovy enum is still
open, right?
Post by Thibault Kruse
Ah, I see. And also I was confused over the primitive int[] arrays not
being acceptable by a method with a generic array parameter.
Post by Jochen Theodorou
Post by Thibault Kruse
Hi,
using groovy 2.4.1 (and earlier), I faced several weird / invalid
errors, some related to IntelliJ, some in Groovy.
class TestGenerics {
static <T> List<T> randomSample(T[] sequence, String a) {
return Arrays.asList(sequence)[0..1]
}
static void main(String[] args) {
List val = randomSample([1, 2, 3] as int[], '1')
}
}
kruset:/tmp $ groovy TestGenerics.groovy
([I, java.lang.String) values: [[1, 2, 3], 1]
If I remove the superfluous String argument, it works fine.
That is because without the String parameter you are doing a "variable
argument" call. Unlike Java in Groovy it is enough to just use an array. But
it needs to be the last parameter. btw, in your case T[] won't be [1,2,3],
but [[1,2,3]]. In other words an Object[] with a single element, which is an
int[]
Post by Thibault Kruse
Sadly the IntelliJ groovy parser seems to be independent of the used
groovyc version, so the visible editor output does not always match
what a given groovyc version will accept.
Should I open a JIRA ticket?
If intellij does not accept the String-less version, then it is a bug. The
case is no different from Java if T... had been used. But of course that
would go in the intellij JIRA, not ours then. Unless I misunderstand you of
course
bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Thibault Kruse
2015-03-02 15:48:15 UTC
Permalink
The second one has the same problem with Lists:

import groovy.transform.TypeChecked

import java.nio.file.StandardCopyOption

@TypeChecked
class TestGenerics {

public static <T> List<T> randomSample(List<T> sequence) {
return Arrays.asList(sequence)[0..1]
}

def test2 = randomSample([StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES])

def static main(String[] a) {}
}

$ groovy TestGenerics.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/tmp/TestGenerics.groovy: 12: [Static type checking] - Cannot call <T>
TestGenerics#randomSample(java.util.List <T>) with arguments
[java.util.List <java.nio.file.StandardCopyOption>]
@ line 12, column 15.
def test2 = randomSample([StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES])
Post by Thibault Kruse
Still the second problem with the Java enum vs. Groovy enum is still
open, right?
Post by Thibault Kruse
Ah, I see. And also I was confused over the primitive int[] arrays not
being acceptable by a method with a generic array parameter.
Post by Jochen Theodorou
Post by Thibault Kruse
Hi,
using groovy 2.4.1 (and earlier), I faced several weird / invalid
errors, some related to IntelliJ, some in Groovy.
class TestGenerics {
static <T> List<T> randomSample(T[] sequence, String a) {
return Arrays.asList(sequence)[0..1]
}
static void main(String[] args) {
List val = randomSample([1, 2, 3] as int[], '1')
}
}
kruset:/tmp $ groovy TestGenerics.groovy
([I, java.lang.String) values: [[1, 2, 3], 1]
If I remove the superfluous String argument, it works fine.
That is because without the String parameter you are doing a "variable
argument" call. Unlike Java in Groovy it is enough to just use an array. But
it needs to be the last parameter. btw, in your case T[] won't be [1,2,3],
but [[1,2,3]]. In other words an Object[] with a single element, which is an
int[]
Post by Thibault Kruse
Sadly the IntelliJ groovy parser seems to be independent of the used
groovyc version, so the visible editor output does not always match
what a given groovyc version will accept.
Should I open a JIRA ticket?
If intellij does not accept the String-less version, then it is a bug. The
case is no different from Java if T... had been used. But of course that
would go in the intellij JIRA, not ours then. Unless I misunderstand you of
course
bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email
Jochen Theodorou
2015-03-02 16:07:13 UTC
Permalink
Post by Thibault Kruse
import groovy.transform.TypeChecked
import java.nio.file.StandardCopyOption
@TypeChecked
class TestGenerics {
public static <T> List<T> randomSample(List<T> sequence) {
return Arrays.asList(sequence)[0..1]
}
def test2 = randomSample([StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES])
def static main(String[] a) {}
}
$ groovy TestGenerics.groovy
/tmp/TestGenerics.groovy: 12: [Static type checking] - Cannot call <T>
TestGenerics#randomSample(java.util.List <T>) with arguments
[java.util.List <java.nio.file.StandardCopyOption>]
@ line 12, column 15.
def test2 = randomSample([StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES])
I wonder why it does not work... well, it looks like a bug on our side
here,yes. JIRA entry welcome.

bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org


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

http://xircles.codehaus.org/manage_email
Thibault Kruse
2015-03-02 16:17:14 UTC
Permalink
Created as https://jira.codehaus.org/browse/GROOVY-7327
Post by Jochen Theodorou
Post by Thibault Kruse
import groovy.transform.TypeChecked
import java.nio.file.StandardCopyOption
@TypeChecked
class TestGenerics {
public static <T> List<T> randomSample(List<T> sequence) {
return Arrays.asList(sequence)[0..1]
}
def test2 = randomSample([StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES])
def static main(String[] a) {}
}
$ groovy TestGenerics.groovy
/tmp/TestGenerics.groovy: 12: [Static type checking] - Cannot call <T>
TestGenerics#randomSample(java.util.List <T>) with arguments
[java.util.List <java.nio.file.StandardCopyOption>]
@ line 12, column 15.
def test2 = randomSample([StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES])
I wonder why it does not work... well, it looks like a bug on our side
here,yes. JIRA entry welcome.
bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Loading...