You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/05/29 22:48:01 UTC
[jira] [Created] (GROOVY-9151) Default Arguments: reference to
another defaulted parameter causes run-time errors
Eric Milles created GROOVY-9151:
-----------------------------------
Summary: Default Arguments: reference to another defaulted parameter causes run-time errors
Key: GROOVY-9151
URL: https://issues.apache.org/jira/browse/GROOVY-9151
Project: Groovy
Issue Type: Bug
Reporter: Eric Milles
Default argument values may be supplied using back references, like this:
{code}
void hello(String s, Object o = s) { println o }
hello('world')
{code}
or this:
{code}
void hello(String s, Object o = new String(s)) { println o }
hello('world')
{code}
However, if the back reference {{s}} also has a default value, Groovy produces nasty errors:
{code}
void hello(String s = 'world', Object o = new String(s)) { println o }
hello() // MissingPropertyException: No such property: s for class: script
{code}
or worse:
{code}
class Thing {
Thing(String s = 'boo', Object o = new String(s)) {
}
}
new Thing()
{code}
{code:java}
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)
{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)