groovy

Strange coersion bug in Groovy shell

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.5.4
  • Fix Version/s: 1.5.5, 1.6-beta-1
  • Component/s: Groovysh
  • Labels:
    None
  • Environment:
    Windows XP
  • Number of attachments :
    0

Description

This expression works properly in Groovy console, but it does not work
in groovysh:
[1,2,3] as Object[]

In groovysh it throws exception:
ERROR groovy.lang.MissingMethodException: No signature of method:
org.codehaus.groovy.tools.shell.Groovysh$_cl
osure1.call() is applicable for argument types: (java.lang.Integer,
java.lang.Integer, java.lang.Integer) valu
es: {1, 2, 3}

However,
[1,2,3] as int[]
works as expected.

[1,2,3] as Integer[]
throws similar exception.

All these expressions work properly in Groovy console.

Activity

Hide
Jason Dillon added a comment -

I'm sure this is because groovysh has some magic in it to try and allow for line by line parsing, where groovyConsole parses full/complete source buffers... not sure how to fix really, we can add more hacks to allow groovysh to behave better, but its just a bandaid.

Show
Jason Dillon added a comment - I'm sure this is because groovysh has some magic in it to try and allow for line by line parsing, where groovyConsole parses full/complete source buffers... not sure how to fix really, we can add more hacks to allow groovysh to behave better, but its just a bandaid.
Hide
Sergey Bondarenko added a comment -

Please look at the following code snippet.
The same thing is happening in Groovysh.
As I understand, there is the problem in Groovy itself (not in Groovysh).

def show = {var -> println var}

def x = [1,2] as Object[]

show( [1,2] as Object[] ) //prints {1, 2}
show.call( [1,2] as Object[] ) //prints {1, 2}

show( x ) //prints {1, 2}
show.call( x ) //throws MissingMethodException !!!

I think all these calls should do the same thing. But the last one throws MissingMethodException.

Show
Sergey Bondarenko added a comment - Please look at the following code snippet. The same thing is happening in Groovysh. As I understand, there is the problem in Groovy itself (not in Groovysh). def show = {var -> println var} def x = [1,2] as Object[] show( [1,2] as Object[] ) //prints {1, 2} show.call( [1,2] as Object[] ) //prints {1, 2} show( x ) //prints {1, 2} show.call( x ) //throws MissingMethodException !!! I think all these calls should do the same thing. But the last one throws MissingMethodException.
Hide
Sergey Bondarenko added a comment -

Could anyone please look at this test case and patch?

Test case for this issue:

package org.codehaus.groovy.tools.shell

import org.codehaus.groovy.tools.shell.Groovysh

def shell = new Groovysh()
shell.execute "[1,2] as Object[]"
assert ([1,2] as Object) == shell.lastResult

Patch (of file Groovysh.groovy):

405c405
< resultHook.call(result)

> resultHook.call((Object)result)

Show
Sergey Bondarenko added a comment - Could anyone please look at this test case and patch? Test case for this issue: package org.codehaus.groovy.tools.shell import org.codehaus.groovy.tools.shell.Groovysh def shell = new Groovysh() shell.execute "[1,2] as Object[]" assert ([1,2] as Object) == shell.lastResult Patch (of file Groovysh.groovy): 405c405 < resultHook.call(result) — > resultHook.call((Object)result)
Hide
Paul King added a comment -

Your suggested patch seems to work for me.

Show
Paul King added a comment - Your suggested patch seems to work for me.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: