Eric Milles created GROOVY-11828:
------------------------------------

             Summary: instanceof variable VerifyError
                 Key: GROOVY-11828
                 URL: https://issues.apache.org/jira/browse/GROOVY-11828
             Project: Groovy
          Issue Type: Bug
          Components: class generator
            Reporter: Eric Milles
            Assignee: Eric Milles


Consider the following:
{code:groovy}
def x = 'foo', y
if (x instanceof String s) {
  y = { -> s + 'bar' }()
}
assert y == 'foobar'
{code}

Use of variable "s" within a closure causes a verify error.

{code}
    java.lang.VerifyError: Bad type on operand stack
    Exception Details:
      Location:
        TestScript0.run()Ljava/lang/Object; @42: invokespecial
      Reason:
        Type 'java/lang/Object' (current frame, stack[4]) is not assignable to 
'groovy/lang/Reference'
      Current Frame:
        bci: @42
        flags: { }
        locals: { 'TestScript0', 'java/lang/String', null, 'java/lang/Object' }
        stack: { uninitialized 35, uninitialized 35, 'TestScript0', 
'TestScript0', 'java/lang/Object' }
      Bytecode:
        0000000: 122d 4c01 4d2b 59c1 002f 01bb 0031 5a5f
        0000010: b700 344e 5a99 000a c000 2f4e a700 0457
        0000020: 9900 13bb 0036 592a 2a2d b700 39ba 003e
        0000030: 0000 4dbb 0040 59b7 0041 3a04 2c59 1904
        0000040: 5f12 42b6 0046 5712 48b8 004e 59b8 0054
        0000050: 1904 5f12 55b6 0046 5799 000b 1904 b600
        0000060: 58a7 0015 125a 1904 b800 6001 b800 64bf
        0000070: 1904 b600 58bf 01b0
      Exception Handler Table:
        bci [60, 112] => handler: 112
      Stackmap Table:
        
full_frame(@31,{Object[#2],Object[#47],Null,Object[#49]},{Integer,Object[#47]})
        full_frame(@32,{Object[#2],Object[#47],Null,Object[#107]},{Integer})
        full_frame(@51,{Object[#2],Object[#47],Object[#107],Object[#107]},{})
        append_frame(@100,Object[#64])
        same_locals_1_stack_item_frame(@112,Object[#109])
        same_frame(@118)
        at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
        at 
java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3373)
        at java.base/java.lang.Class.getConstructor0(Class.java:3578)
        at java.base/java.lang.Class.getConstructor(Class.java:2271)
        at 
org.codehaus.groovy.runtime.InvokerHelper.newScript(InvokerHelper.java:498)
        at 
org.codehaus.groovy.runtime.InvokerHelper.createScript(InvokerHelper.java:448)
        at groovy.lang.GroovyShell.parse(GroovyShell.java:614)
        at groovy.lang.GroovyShell.parse(GroovyShell.java:626)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:488)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:524)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:508)
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to