groovy

'abc'++ throws Error

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0
  • Fix Version/s: 1.1-rc-2
  • Component/s: groovy-jdk
  • Labels:
    None
  • Environment:
    Mac OS X; JDK 1.5; Groovy 1.0 _and_ Groovy 1.1b2
  • Number of attachments :
    0

Description

Execute "println 'abc'++" and you'll get an error (see below). 'abc'.next() will do. Same thing with 'abc'-- and 'abc.previous()

groovy> println 'abc'++

Exception thrown: java.lang.VerifyError: (class: Script0, method: run signature: ()Ljava/lang/Object Expecting to find integer on stack

java.lang.VerifyError: (class: Script0, method: run signature: ()Ljava/lang/Object Expecting to find integer on stack
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2328)
at java.lang.Class.getConstructor0(Class.java:2640)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:421)
at groovy.lang.GroovyShell.parse(GroovyShell.java:525)
at groovy.lang.GroovyShell.parse(GroovyShell.java:505)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:483)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:425)
at gjdk.groovy.lang.GroovyShell_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:115)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:131)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:187)
at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy:503)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:69)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:97)
at groovy.ui.Console$_runScript_closure10.doCall(Console.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:69)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:713)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:560)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:450)
at groovy.lang.Closure.call(Closure.java:188)
at groovy.lang.Closure.call(Closure.java:183)
at groovy.lang.Closure.run(Closure.java:264)
at java.lang.Thread.run(Thread.java:613)

Activity

Hide
Hamlet D'Arcy added a comment -

what is the expected output of 'abc'++

are you expected it to evaluate the same as 'abc' + 1 ?

Show
Hamlet D'Arcy added a comment - what is the expected output of 'abc'++ are you expected it to evaluate the same as 'abc' + 1 ?
Hide
Bernd Schiffer added a comment -

Hamlet, probably not that it throws such an exception, I think Seriously I would expect the same behaviour than calling 'abc'.next(), which is 'abd' and increments the last character whereas 'abc' + 1 results in 'abc1' and is not the same than 'abc'.next()

Show
Bernd Schiffer added a comment - Hamlet, probably not that it throws such an exception, I think Seriously I would expect the same behaviour than calling 'abc'.next(), which is 'abd' and increments the last character whereas 'abc' + 1 results in 'abc1' and is not the same than 'abc'.next()
Hide
Hamlet D'Arcy added a comment -

'abc' in Groovy in an instance of a java.lang.String

I'm not sure what the 'least surprising result' of 'abc'++ is. Perhaps an exception is the least surprising result.

Lisp and Ruby both throw an exception trying to increment a string by one. But I can see the point in having lhs++ and lhs-- work the same as lhs + 1 and lhs - 1.

Thoughts anyone?

Show
Hamlet D'Arcy added a comment - 'abc' in Groovy in an instance of a java.lang.String I'm not sure what the 'least surprising result' of 'abc'++ is. Perhaps an exception is the least surprising result. Lisp and Ruby both throw an exception trying to increment a string by one. But I can see the point in having lhs++ and lhs-- work the same as lhs + 1 and lhs - 1. Thoughts anyone?
Hide
Bernd Schiffer added a comment -

Hamlet, in fact I don't want to change the behaviour of string++. If you want to do that, please raise another issue or discuss it on the mailing list. The thing I mention here is, that

println 'abc'.next()

prints abd, and

println 'abc'++

throws an java.lang.VerifyError. That's my point here.

Show
Bernd Schiffer added a comment - Hamlet, in fact I don't want to change the behaviour of string++. If you want to do that, please raise another issue or discuss it on the mailing list. The thing I mention here is, that println 'abc'.next() prints abd, and println 'abc'++ throws an java.lang.VerifyError. That's my point here.
Hide
blackdrag blackdrag added a comment -

fixed... it prints abd now

Show
blackdrag blackdrag added a comment - fixed... it prints abd now

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: