quarkusio/gizmo

FunctionCreator - incorrecly allocated captured values inside an if statement

Closed this issue · 3 comments

If you create a function with capture with an if statement inside the method body and attempt to use the captured result handles inside the statement you'll get java.lang.VerifyError: Bad local variable type.

The generated bytecode looks like this:

Method get : Ljava/lang/Object;
(
    // (no arguments)
) {
    ** label1
    ** label2
    LDC (Boolean) true
    IFNE label3
    ** label4
    ** label5
    GOTO label6
    ** label3
    ALOAD 1
    LDC (String) "-func"
    // Method descriptor: (Ljava/lang/String;)Ljava/lang/String;
    INVOKEVIRTUAL java/lang/String#concat
    ARETURN
    ** label6
    ALOAD 0
    // Field descriptor: Ljava/lang/String;
    GETFIELD com/MyTest$$function$$3#f0
    ASTORE 1
    ACONST_NULL
    ARETURN
    ** label7
    ** label8
 }

Note that the captured result handle is allocated after IFNE.

I'll send a PR with the test but I'm not sure how to fix this properly.

A workaround is to create a local variable inside the function body (before the if statement), assign the captured value and use the variable inside the if block.

I will try and look at this tomorrow

Thanks! It's not a high priority...