jaccomoc/jactl

Invoking method on a primitive variable in outer-scope from within a closure leads to JVM validation error

Closed this issue · 0 comments

Invoking a method on a primitive variable (int, long, etc) inside a closure/function where the variable is declared outside the closure will lead to a validation error.
For example:

int x = 1;
def f() { x.each{ println it } }
f()

Leads to this error at compile time:

...
Caused by: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    io/jactl/pkg/_$j$Script84844589BD60113AF258DBE09E0C9E3D._$j$main$f(Lio/jactl/runtime/HeapLocal;)Ljava/lang/Object; @5: ifnonnull
  Reason:
    Type integer (current frame, stack[1]) is not assignable to reference type
  Current Frame:
    bci: @5
    flags: { }
    locals: { 'io/jactl/pkg/_$j$Script84844589BD60113AF258DBE09E0C9E3D', 'io/jactl/runtime/HeapLocal' }
    stack: { integer, integer }
  Bytecode:
    0000000: 2bb6 004a 59c7 0012 57bb 004c 5912 4e12
    0000010: 5010 17b7 0053 bfb8 0036 01b8 0059 b800
    0000020: 36b0                                   
  Stackmap Table:
    same_locals_1_stack_item_frame(@23,Integer)