You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2022/04/01 14:23:00 UTC
[jira] [Comment Edited] (GROOVY-10558) Wrong argument type when using static method from nested class
[ https://issues.apache.org/jira/browse/GROOVY-10558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17515944#comment-17515944 ]
Eric Milles edited comment on GROOVY-10558 at 4/1/22 2:22 PM:
--------------------------------------------------------------
The compiler adds "methodMissing" as seen below to handle outer class method references. It is the spread over {{args}} which converts the byte array into individual byte arguments.
{code:groovy}
class Example {
static byte[] hash(byte[] bytes) {
bytes
}
static class Nested {
def getCacheKey(byte[] payload) {
hash(payload)
}
def methodMissing(String name, args) {
return Example."$name"(*args)
}
}
}
{code}
was (Author: emilles):
The compiler adds "methodMissing" as seen below. It is the spread over {{args}} which converts the byte array into individual byte arguments.
{code:groovy}
class Example {
static byte[] hash(byte[] bytes) {
bytes
}
static class Nested {
def getCacheKey(byte[] payload) {
hash(payload)
}
def methodMissing(String name, args) {
return Example."$name"(*args)
}
}
}
{code}
> Wrong argument type when using static method from nested class
> --------------------------------------------------------------
>
> Key: GROOVY-10558
> URL: https://issues.apache.org/jira/browse/GROOVY-10558
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.16, 3.0.10, 4.0.1
> Reporter: Leonard Brünings
> Assignee: Eric Milles
> Priority: Major
>
> {code:groovy}
> class Example {
> static byte[] hash(byte[] bytes) {
> bytes
> }
> static class Nested {
> def getCacheKey(byte[] payload) {
> hash(payload)
> // hash(payload as byte[]) fails as well
> // Example.hash(payload) works
> }
> }
> }
> new Example.Nested().getCacheKey("bar".bytes)
> {code}
> fails with
> {noformat}
> groovy.lang.MissingMethodException: No signature of method: static Example.hash() is applicable for argument types: (ArrayList) values: [[98, 97, 114]]
> Possible solutions: hash([B), each(groovy.lang.Closure), wait(), any(), wait(long), is(java.lang.Object)
> at Example$Nested.methodMissing(Script1.groovy)
> at Example$Nested.getCacheKey(Script1.groovy:7)
> at Example$Nested$getCacheKey.call(Unknown Source)
> at Script1.run(Script1.groovy:14)
> {noformat}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)