static closure value access fails => BUG?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

static closure value access fails => BUG?

calathus
Hi,
I found some basic strange behavior of Groovy. following code will fails (I tested using the latest cvs)
the static closure value seems not properly handled compared to that case of instance closure value . see the difference the foo1 and soo1.

---
program:

public class Simple1 {
    public static def soo0(x) {x+x}
    public static def soo1 ={x|x+x}
    def foo0(x) {x+x}
    def foo1 = {x| x+x}
}

println(">> new Simple1().foo0(5):"+new Simple1().foo0(5)) // works
println(">> new Simple1().foo1(5):"+new Simple1().foo1(5)) // works

println(">> Simple1.soo0(5): "+Simple1.soo0(5)) // works
println(">> Simple1.soo1(5):"+Simple1.soo1(5)) // fails


-------
execution log:

>> new Simple1().foo0(5):10
>> new Simple1().foo1(5):10
>> Simple1.soo0(5): 10
Exception in thread "main" groovy.lang.MissingMethodException : No signature of method Simple1.soo1() is applicable for argument types: (java.lang.Integer) values: {5}
    at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:493)
    at org.codehaus.groovy.runtime.Invoker.invokeMethod (Invoker.java:136)
    at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
    at test_case_0.run(test_case_0.groovy:13)
    at gjdk.test_case_0_GroovyReflector.invoke(Unknown Source)
    at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
    at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:657)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:350)
    at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
    at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java :104)
    at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:516)
    at gjdk.org.codehaus.groovy.runtime.InvokerHelper_GroovyReflector.invoke(Unknown Source)
    at groovy.lang.MetaMethod.invoke (MetaMethod.java:111)
    at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:657)
    at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:490)
    at org.codehaus.groovy.runtime.Invoker.invokeMethod (Invoker.java:136)
    at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
    at test_case_0.main(test_case_0.groovy)

--
Cheer
Calathus

"Imagination is more important than knowledge." -- A. Einstein
"Everything should be made as simple as possible, but not simpler."  -- A. Einstein
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." -- A. Einstein
Reply | Threaded
Open this post in threaded view
|

Re: static closure value access fails => BUG?

Guillaume Laforge
Administrator
At first glance, it looks like a bug.
That should be entered in JIRA :-)

On 4/2/06, calathus <[hidden email]> wrote:

> Hi,
> I found some basic strange behavior of Groovy. following code will fails (I
> tested using the latest cvs)
> the static closure value seems not properly handled compared to that case of
> instance closure value . see the difference the foo1 and soo1.
>
> ---
> program:
>
> public class Simple1 {
>     public static def soo0(x) {x+x}
>     public static def soo1 ={x|x+x}
>     def foo0(x) {x+x}
>     def foo1 = {x| x+x}
> }
>
> println(">> new Simple1().foo0(5):"+new Simple1().foo0(5)) // works
> println(">> new Simple1().foo1(5):"+new Simple1().foo1(5)) // works
>
> println(">> Simple1.soo0(5): "+Simple1.soo0(5)) // works
> println(">> Simple1.soo1(5):"+Simple1.soo1(5)) // fails
>
>
> -------
> execution log:
>
> >> new Simple1().foo0(5):10
> >> new Simple1().foo1(5):10
> >> Simple1.soo0(5): 10
> Exception in thread "main"
> groovy.lang.MissingMethodException : No signature of method
> Simple1.soo1() is applicable for argument types: (java.lang.Integer) values:
> {5}
>     at
> groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:493)
>     at org.codehaus.groovy.runtime.Invoker.invokeMethod
> (Invoker.java:136)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
>     at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>     at test_case_0.run(test_case_0.groovy:13)
>     at gjdk.test_case_0_GroovyReflector.invoke(Unknown
> Source)
>     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
>     at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:657)
>     at
> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:350)
>     at
> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java
> :104)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:516)
>     at
> gjdk.org.codehaus.groovy.runtime.InvokerHelper_GroovyReflector.invoke(Unknown
> Source)
>     at groovy.lang.MetaMethod.invoke (MetaMethod.java:111)
>     at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:657)
>     at
> groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:490)
>     at org.codehaus.groovy.runtime.Invoker.invokeMethod
> (Invoker.java:136)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:104)
>     at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>     at test_case_0.main(test_case_0.groovy)
>
> --
> Cheer
> Calathus
>
> "Imagination is more important than knowledge." -- A. Einstein
> "Everything should be made as simple as possible, but not simpler."  -- A.
> Einstein
> "Any intelligent fool can make things bigger, more complex, and more
> violent. It takes a touch of genius -- and a lot of courage -- to move in
> the opposite direction." -- A. Einstein


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy
Reply | Threaded
Open this post in threaded view
|

Re: static closure value access fails => BUG?

calathus
Guillaume,
I tested this, but I found several similar problem I reported as BUG.

Basically if we define variable of closure value, and try to evaluate it, it fails for both static and instance def.

BTW, I think this current handling of instance def as default is rather confusing and different from Java.
In Java, if we define something under top level file, it is handled as static without explicit declaration
For actual usage case, it is inconvenient to always specify static for access def and it is strange also to create an instance 'file' to access the instance property. I think this spec should be changed.(I have not tested, but also those def should be public as default for ease of use)
---

following is the result.

-----
simple.groovy:

public static def gsoo0(x) {x+x}
public static def gsoo1 = {x| x+x}

public def gfoo0(x) {x+x}
public def gfoo1 = {x| x+x}

public class Simple {
    public static def soo0(x) {x+x}
    public static def soo1 ={x|x+x}
    def foo0(x) {x+x}
    def foo1 = {x| x+x}
}
-----
test3.groovy:

println(">> new simple().gfoo0(5):"+new simple().gfoo0(5)) // works
//println(">> new simple().gfoo1(5):"+new simple().gfoo1(5)) // fails

println(">> simple1.gsoo0(5): "+simple.gsoo0(5)) // works
//println(">> simple1.sgoo1(5):"+simple.gsoo1(5)) // fails

println(">> new Simple1().foo0(5):"+new Simple1().foo0(5)) // works
println(">> new Simple1().foo1(5):"+new Simple1().foo1(5)) // works

println(">> Simple1.soo0 (5): "+Simple1.soo0(5)) // works
println(">> Simple1.soo1(5):"+Simple1.soo1(5)) // fails


On 4/3/06, Guillaume Laforge <[hidden email]> wrote:
At first glance, it looks like a bug.
That should be entered in JIRA :-)

On 4/2/06, calathus <[hidden email]> wrote:

> Hi,
> I found some basic strange behavior of Groovy. following code will fails (I
> tested using the latest cvs)
> the static closure value seems not properly handled compared to that case of
> instance closure value . see the difference the foo1 and soo1.
>
> ---
> program:
>
> public class Simple1 {
>     public static def soo0(x) {x+x}
>     public static def soo1 ={x|x+x}
>     def foo0(x) {x+x}
>     def foo1 = {x| x+x}
> }
>
> println(">> new Simple1().foo0(5):"+new Simple1().foo0(5)) // works
> println(">> new Simple1().foo1(5):"+new Simple1().foo1(5)) // works
>
> println(">> Simple1.soo0(5): "+Simple1.soo0(5)) // works
> println(">> Simple1.soo1 (5):"+Simple1.soo1(5)) // fails
>
>
> -------
> execution log:
>
> >> new Simple1().foo0(5):10
> >> new Simple1().foo1(5):10
> >> Simple1.soo0(5): 10
> Exception in thread "main"

> groovy.lang.MissingMethodException : No signature of method
> Simple1.soo1() is applicable for argument types: (java.lang.Integer) values:
> {5}
>     at
> groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:493)
>     at org.codehaus.groovy.runtime.Invoker.invokeMethod
> (Invoker.java:136)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java:104)
>     at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>     at test_case_0.run(test_case_0.groovy:13)
>     at gjdk.test_case_0_GroovyReflector.invoke (Unknown
> Source)
>     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
>     at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:657)
>     at
> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:350)
>     at
> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java
> :104)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:516)
>     at
> gjdk.org.codehaus.groovy.runtime.InvokerHelper_GroovyReflector.invoke (Unknown
> Source)
>     at groovy.lang.MetaMethod.invoke (MetaMethod.java:111)
>     at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:657)
>     at
> groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:490)
>     at org.codehaus.groovy.runtime.Invoker.invokeMethod
> (Invoker.java:136)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java:104)
>     at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>     at test_case_0.main(test_case_0.groovy)
>
> --
> Cheer
> Calathus
>
> "Imagination is more important than knowledge." -- A. Einstein
> "Everything should be made as simple as possible, but not simpler."  -- A.
> Einstein
> "Any intelligent fool can make things bigger, more complex, and more
> violent. It takes a touch of genius -- and a lot of courage -- to move in
> the opposite direction." -- A. Einstein


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy



--
Calathus
Reply | Threaded
Open this post in threaded view
|

Re: static closure value access fails => BUG?

calathus

BTW, I think this current handling of instance def as default is rather confusing and different from Java.
In Java, if we define something under top level file, it is handled as static without explicit declaration
For actual usage case, it is inconvenient to always specify static for access def and it is strange also to create an instance 'file' to access the instance property. I think this spec should be changed.(I have not tested, but also those def should be public as default for ease of use)

Maybe this is a confusing statement, in Java, global level for declarations, but in groovy, it is  local execution block. but sometimes, it is going to be a mixture of statement and declaration.
this seems dirty grey zone...
anyway, just including other groovy files would be simpler and avoid this sort of problems.

C
 

---

following is the result.

-----
simple.groovy:

public static def gsoo0(x) {x+x}
public static def gsoo1 = {x| x+x}

public def gfoo0(x) {x+x}
public def gfoo1 = {x| x+x}

public class Simple {

    public static def soo0(x) {x+x}
    public static def soo1 ={x|x+x}
    def foo0(x) {x+x}
    def foo1 = {x| x+x}
}
-----
test3.groovy:

println(">> new simple().gfoo0(5):"+new simple().gfoo0(5)) // works
//println(">> new simple().gfoo1(5):"+new simple().gfoo1(5)) // fails

println(">> simple1.gsoo0(5): "+simple.gsoo0(5)) // works
//println(">> simple1.sgoo1(5):"+simple.gsoo1(5)) // fails


println(">> new Simple1().foo0(5):"+new Simple1().foo0(5)) // works
println(">> new Simple1().foo1(5):"+new Simple1().foo1(5)) // works

println(">> Simple1.soo0 (5): "+Simple1.soo0(5)) // works
println(">> Simple1.soo1(5):"+Simple1.soo1(5)) // fails


On 4/3/06, Guillaume Laforge <[hidden email]> wrote:
At first glance, it looks like a bug.
That should be entered in JIRA :-)

On 4/2/06, calathus <[hidden email]> wrote:

> Hi,
> I found some basic strange behavior of Groovy. following code will fails (I
> tested using the latest cvs)
> the static closure value seems not properly handled compared to that case of
> instance closure value . see the difference the foo1 and soo1.
>
> ---
> program:
>
> public class Simple1 {
>     public static def soo0(x) {x+x}
>     public static def soo1 ={x|x+x}
>     def foo0(x) {x+x}
>     def foo1 = {x| x+x}
> }
>
> println(">> new Simple1().foo0(5):"+new Simple1().foo0(5)) // works
> println(">> new Simple1().foo1(5):"+new Simple1().foo1(5)) // works
>
> println(">> Simple1.soo0(5): "+Simple1.soo0(5)) // works
> println(">> Simple1.soo1 (5):"+Simple1.soo1(5)) // fails
>
>
> -------
> execution log:
>
> >> new Simple1().foo0(5):10
> >> new Simple1().foo1(5):10
> >> Simple1.soo0(5): 10
> Exception in thread "main"

> groovy.lang.MissingMethodException : No signature of method
> Simple1.soo1() is applicable for argument types: (java.lang.Integer) values:
> {5}
>     at
> groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:493)
>     at org.codehaus.groovy.runtime.Invoker.invokeMethod
> (Invoker.java:136)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java:104)
>     at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>     at test_case_0.run(test_case_0.groovy:13)
>     at gjdk.test_case_0_GroovyReflector.invoke (Unknown
> Source)
>     at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
>     at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:657)
>     at
> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:350)
>     at
> org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:156)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java
> :104)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:516)
>     at
> gjdk.org.codehaus.groovy.runtime.InvokerHelper_GroovyReflector.invoke (Unknown
> Source)
>     at groovy.lang.MetaMethod.invoke (MetaMethod.java:111)
>     at
> org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:657)
>     at
> groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:490)
>     at org.codehaus.groovy.runtime.Invoker.invokeMethod
> (Invoker.java:136)
>     at
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod (InvokerHelper.java:104)
>     at
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod(ScriptBytecodeAdapter.java:85)
>     at test_case_0.main(test_case_0.groovy)
>
> --
> Cheer
> Calathus
>
> "Imagination is more important than knowledge." -- A. Einstein
> "Everything should be made as simple as possible, but not simpler."  -- A.
> Einstein
> "Any intelligent fool can make things bigger, more complex, and more
> violent. It takes a touch of genius -- and a lot of courage -- to move in
> the opposite direction." -- A. Einstein


--
Guillaume Laforge
Groovy Project Manager
<a href="http://glaforge.free.fr/blog/groovy" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)"> http://glaforge.free.fr/blog/groovy



--
Calathus



--
Calathus