leibnitz27 / cfr

This is the public repository for the CFR Java decompiler
https://www.benf.org/other/cfr
MIT License
1.93k stars 249 forks source link

Local records are defined after being used as a generic type. #275

Open modmuss50 opened 2 years ago

modmuss50 commented 2 years ago

CFR version

CFR 0.151 & lastest master at time of issue: 3d6b0c88835402de40423d13d495bcef07daae72

Compiler

javac 17

Description

Note in the simple example bellow that the local record LocalRecord is defined after its beign used as a generic type to List. Also note that the listOfRecords varible type was decompiled as ArrayList while it was originally written as List

Example

package example;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String... args) {
        record LocalRecord(int abc) { }
        List<LocalRecord> listOfRecords = new ArrayList<>();

        listOfRecords.add(new LocalRecord(123));

        for (LocalRecord r : listOfRecords) {
            System.out.println(r.abc());
        }
    }
}

Decompiles to:

/*
 * Decompiled with CFR 0.151.
 */
package example;

import java.util.ArrayList;

public class Main {
    public static void main(String ... args) {
        ArrayList<LocalRecord> listOfRecords = new ArrayList<LocalRecord>();
        record LocalRecord(int abc) {
        }
        listOfRecords.add(new LocalRecord(123));
        for (LocalRecord r : listOfRecords) {
            System.out.println(r.abc());
        }
    }
}