Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFR generates duplicate variable names inside and outside lambda expressions #339

Open
xxh160 opened this issue Apr 24, 2023 · 0 comments
Open
Labels

Comments

@xxh160
Copy link

xxh160 commented Apr 24, 2023

Hi! I am doing some research based on CFR, and I found a bug related to lambda expressions.

When decompiling lambda expressions, CFR generates duplicate variable names for variables that have the same name outside of the lambda expression.

This leads to compilation errors when trying to compile the decompiled code.

Here is an example:

interface I1 {
    void apply();
}
class Demo {
    public void foo() {
        Character c1= 'c';
        I1 i1 = () -> {
            Character c2 = 'c';
        };
    }
}

When decompiling the above code with CFR, the generated code contains a duplicate variable name c inside and outside of the lambda expression:

/*
 * Decompiled with CFR 0.153-SNAPSHOT (24c7433-dirty).
 */
class Demo {
    Demo() {
    }
    public void foo() {
        Character c = Character.valueOf('c');
        I1 i1 = () -> {
            Character c = Character.valueOf('c');
        };
    }
}

When I tried to compile the decompiled code, a compilation error occurred:

./Demo.java:11: error: variable c is already defined in method foo()
            Character c = Character.valueOf('c');
                      ^
1 error

Would you please have a look at this? It is important for me!
Thanks a lot!

CFR version: CFR 0.153-SNAPSHOT (24c7433-dirty).
Javac version: openjdk 11.0.18 2023-01-17.
I also attach the source files and the decompilation results and I hope they will be helpful: demo.zip.

@xxh160 xxh160 added the bug label Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant