Issue Details (XML | Word | Printable)

Key: GROOVY-2079
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Bernd Schiffer
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

'abc'++ throws Error

Created: 24/Aug/07 04:25 PM   Updated: 28/Oct/07 01:25 PM
Component/s: groovy-jdk
Affects Version/s: 1.0
Fix Version/s: 1.1-rc-2

Time Tracking:
Not Specified

Environment: Mac OS X; JDK 1.5; Groovy 1.0 _and_ Groovy 1.1b2


 Description  « Hide
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)



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Hamlet D'Arcy added a comment - 18/Oct/07 09:04 AM
what is the expected output of 'abc'++

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


Bernd Schiffer added a comment - 18/Oct/07 09:59 AM
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()

Hamlet D'Arcy added a comment - 18/Oct/07 10:21 AM
'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?


Bernd Schiffer added a comment - 18/Oct/07 10:50 AM
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.


Jochen Theodorou added a comment - 28/Oct/07 01:25 PM
fixed... it prints abd now