Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
Default argument values may be supplied using back references, like this:
void hello(String s, Object o = s) { println o } hello('world')
or this:
void hello(String s, Object o = new String(s)) { println o } hello('world')
However, if the back reference s also has a default value, Groovy produces nasty errors:
void hello(String s = 'world', Object o = new String(s)) { println o } hello() // MissingPropertyException: No such property: s for class: script
or worse:
class Thing { Thing(String s = 'boo', Object o = new String(s)) { } } new Thing()
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack Exception Details: Location: Thing.<init>()V @21: invokeinterface Reason: Type uninitializedThis (current frame, stack[5]) is not assignable to 'java/lang/Object' Current Frame: bci: @21 flags: { flagThisUninit } locals: { uninitializedThis, '[Lorg/codehaus/groovy/runtime/callsite/CallSite;' } stack: { uninitializedThis, 'java/lang/String', 'org/codehaus/groovy/runtime/callsite/CallSite', 'java/lang/Class', 'org/codehaus/groovy/runtime/callsite/CallSite', uninitializedThis } Bytecode: 0x0000000: b800 154c 2a12 31c0 0027 2b12 3232 1227 0x0000010: 2b12 3332 2ab9 0037 0200 b900 2d03 00b7 0x0000020: 002f b1 at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) at java.lang.Class.getDeclaredConstructors(Class.java:2020) at org.codehaus.groovy.reflection.CachedClass$2$1.run(CachedClass.java:84) at java.security.AccessController.doPrivileged(Native Method) at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:82) at org.codehaus.groovy.reflection.CachedClass$2.initValue(CachedClass.java:79) at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:49) at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:36) at org.codehaus.groovy.reflection.CachedClass.getConstructors(CachedClass.java:295) at groovy.lang.MetaClassImpl.<init>(MetaClassImpl.java:232) at groovy.lang.MetaClassImpl.<init>(MetaClassImpl.java:242) at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createNormalMetaClass(MetaClassRegistry.java:171) at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.createWithCustomLookup(MetaClassRegistry.java:161) at groovy.lang.MetaClassRegistry$MetaClassCreationHandle.create(MetaClassRegistry.java:144) at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:288) at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:331) at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:277) at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:905) at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallConstructorSite(CallSiteArray.java:86) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:59) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:238) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:242) at script.run(script.groovy:5)
Attachments
Issue Links
- links to