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

[core] Kotlin - Undefined parametrized types #1800

Closed
bagipro opened this issue Mar 14, 2023 · 3 comments
Closed

[core] Kotlin - Undefined parametrized types #1800

bagipro opened this issue Mar 14, 2023 · 3 comments
Assignees
Labels
bug Core Issues in jadx-core module
Milestone

Comments

@bagipro
Copy link
Collaborator

bagipro commented Mar 14, 2023

Hey!

APK: https://drive.google.com/file/d/1NEIPWFwukzv1BgJDHpaqKZAznMf25lqW/view?usp=sharing

Jadx generates a lot of type declarations without specifying parametrized types, such as kotlin.sequences.SequencesKt___SequencesKt$zipWithNext$1:

public final class SequencesKt___SequencesKt$zipWithNext$1 extends kotlin.jvm.internal.Lambda implements kotlin.jvm.functions.Function2<T, T, kotlin.Tuples<? extends T, ? extends T>> {
    public static final kotlin.sequences.SequencesKt___SequencesKt$zipWithNext$1 INSTANCE = new kotlin.sequences.SequencesKt___SequencesKt$zipWithNext$1();

    public SequencesKt___SequencesKt$zipWithNext$1() {
        super(2);
    }

    @Override
    @org.jetbrains.annotations.NotNull
    public final kotlin.Tuples<T, T> invoke(T t, T t2) {
        return kotlin.TuplesKt.to(t, t2);
    }
}

Another example is in class androidx.collection.SparseArrayKt$keyIterator$1:

public final class SparseArrayKt$keyIterator$1 extends kotlin.collections.IntIterator {
    final androidx.collection.SparseArrayCompat $this_keyIterator;
    private int index;

    public SparseArrayKt$keyIterator$1(androidx.collection.SparseArrayCompat<T> sparseArrayCompat) {
        this.$this_keyIterator = sparseArrayCompat;
    }

All T types here are undefined. It breaks all code logic such as inherited methods

@bagipro bagipro added bug Core Issues in jadx-core module labels Mar 14, 2023
@bagipro bagipro changed the title [core] Kotlin - Undefined parametrized type [core] Kotlin - Undefined parametrized types Mar 14, 2023
@skylot
Copy link
Owner

skylot commented Mar 15, 2023

@bagipro looks like this class should be inlined and use outer method generic. But because this lambda used by instance field, inline not yet supported, this mentioned in #523. I will increase priority of this case.
Another issue: if class inlining is disabled or not possible, jadx needs to ignore unknown generics to make resulting code correct, this should be fixed also.

@skylot skylot self-assigned this Mar 15, 2023
@skylot skylot added this to the TBD milestone Mar 15, 2023
@skylot
Copy link
Owner

skylot commented Mar 17, 2023

@bagipro I commit a fix for second issue: add missing type parameter declarations, code should be correct now 🙂

@skylot
Copy link
Owner

skylot commented Mar 24, 2023

Ok, I implement class inlining by instance field 🎉
Although for Kotlin lambdas it changes code semantic by removing extend of kotlin.jvm.internal.Lambda class, this class hold arity property and used somewhere in Kotlin runtime. After some checks I think it is safe to perform inline, but just in case I add option to disable of inling Kotlin lambdas: --no-inline-kotlin-lambda in cli and Allow to inline Kotlin Lambdas in gui.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module
Projects
None yet
Development

No branches or pull requests

2 participants