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

[kotlin] KInvocationExprent can't be cast to FieldExprent #428

Open
solonovamax opened this issue Sep 6, 2024 · 0 comments
Open

[kotlin] KInvocationExprent can't be cast to FieldExprent #428

solonovamax opened this issue Sep 6, 2024 · 0 comments
Labels
Priority: Medium Medium priority Subsystem: Plugins/Kotlin Anything specifically concerning the Kotlin plugin Subsystem: Writing Anything concerning how expressions are written Type: Bug Something isn't working

Comments

@solonovamax
Copy link

solonovamax commented Sep 6, 2024

Vineflower version

1.11.0+local (built from latest git commit)

Describe the bug

When decompiling the kotlin code

this::class.starProjectedType

the error

java.lang.ClassCastException: class org.vineflower.kotlin.expr.KInvocationExprent cannot be cast to class org.jetbrains.java.decompiler.modules.decompiler.exps.FieldExprent (org.vineflower.kotlin.expr.KInvocationExprent is in unnamed module of loader org.jetbrains.java.decompiler.main.plugins.InJarClassLoader @61e4705b; org.jetbrains.java.decompiler.modules.decompiler.exps.FieldExprent is in unnamed module of loader 'app')
  at org.vineflower.kotlin.expr.KFunctionExprent.toJava(KFunctionExprent.java:97)
  at org.jetbrains.java.decompiler.modules.decompiler.exps.FunctionExprent.wrapOperandString(FunctionExprent.java:747)
  at org.jetbrains.java.decompiler.modules.decompiler.exps.FunctionExprent.wrapOperandString(FunctionExprent.java:716)

is emitted

Additional information

The code I encountered this with was (with everything irrelevant removed):

import kotlin.reflect.full.starProjectedType

fun Any.toJsonElement() {
    this::class.starProjectedType
}

however this is not an issue with extension functions, as it still has the same error with the following code:

import kotlin.reflect.full.starProjectedType

public class Test {
    public fun test() {
        this::class.starProjectedType
    }
}

the decompiled result of each of those, respectively, is as follows:

import kotlin.reflect.full.KClassifiers

internal fun Any.toJsonElement() {
   // $VF: Couldn't be decompiled
   // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
   // java.lang.ClassCastException: class org.vineflower.kotlin.expr.KInvocationExprent cannot be cast to class org.jetbrains.java.decompiler.modules.decompiler.exps.FieldExprent (org.vineflower.kotlin.expr.KInvocationExprent is in unnamed module of loader org.jetbrains.java.decompiler.main.plugins.InJarClassLoader @61e4705b; org.jetbrains.java.decompiler.modules.decompiler.exps.FieldExprent is in unnamed module of loader 'app')
   //   at org.vineflower.kotlin.expr.KFunctionExprent.toJava(KFunctionExprent.java:97)
   //   at org.jetbrains.java.decompiler.modules.decompiler.exps.FunctionExprent.wrapOperandString(FunctionExprent.java:747)
   //   at org.jetbrains.java.decompiler.modules.decompiler.exps.FunctionExprent.wrapOperandString(FunctionExprent.java:716)
   //
   // Bytecode:
   // 00: aload 0
   // 01: ldc "<this>"
   // 03: invokestatic kotlin/jvm/internal/Intrinsics.checkNotNullParameter (Ljava/lang/Object;Ljava/lang/String;)V
   // 06: aload 0
   // 07: invokevirtual java/lang/Object.getClass ()Ljava/lang/Class;
   // 0a: invokestatic kotlin/jvm/internal/Reflection.getOrCreateKotlinClass (Ljava/lang/Class;)Lkotlin/reflect/KClass;
   // 0d: checkcast kotlin/reflect/KClassifier
   // 10: invokestatic kotlin/reflect/full/KClassifiers.getStarProjectedType (Lkotlin/reflect/KClassifier;)Lkotlin/reflect/KType;
   // 13: pop
   // 14: return
}

and

import kotlin.reflect.full.KClassifiers

class Test {
   public fun test() {
      // $VF: Couldn't be decompiled
      // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
      // java.lang.ClassCastException: class org.vineflower.kotlin.expr.KInvocationExprent cannot be cast to class org.jetbrains.java.decompiler.modules.decompiler.exps.FieldExprent (org.vineflower.kotlin.expr.KInvocationExprent is in unnamed module of loader org.jetbrains.java.decompiler.main.plugins.InJarClassLoader @61e4705b; org.jetbrains.java.decompiler.modules.decompiler.exps.FieldExprent is in unnamed module of loader 'app')
      //   at org.vineflower.kotlin.expr.KFunctionExprent.toJava(KFunctionExprent.java:97)
      //   at org.jetbrains.java.decompiler.modules.decompiler.exps.FunctionExprent.wrapOperandString(FunctionExprent.java:747)
      //   at org.jetbrains.java.decompiler.modules.decompiler.exps.FunctionExprent.wrapOperandString(FunctionExprent.java:716)
      //
      // Bytecode:
      // 0: aload 0
      // 1: invokevirtual java/lang/Object.getClass ()Ljava/lang/Class;
      // 4: invokestatic kotlin/jvm/internal/Reflection.getOrCreateKotlinClass (Ljava/lang/Class;)Lkotlin/reflect/KClass;
      // 7: checkcast kotlin/reflect/KClassifier
      // a: invokestatic kotlin/reflect/full/KClassifiers.getStarProjectedType (Lkotlin/reflect/KClassifier;)Lkotlin/reflect/KType;
      // d: pop
      // e: return
   }
}

I believe the issue has something to do with the starProjectedType

Attempting to decompile it with quiltflower produces the following result (respectively):

import kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Reflection;
import kotlin.reflect.KClassifier;
import kotlin.reflect.full.KClassifiers;
import org.jetbrains.annotations.NotNull;

@Metadata(
   mv = {1, 8, 0},
   k = 2,
   xi = 48,
   d1 = {"\u0000\f\n\u0000\n\u0002\u0010\u0002\n\u0002\u0010\u0000\n\u0000\u001a\f\u0010\u0000\u001a\u00020\u0001*\u00020\u0002H\u0000¨\u0006\u0003"},
   d2 = {"toJsonElement", "", "", "nyx"}
)
public final class SerializationUtilKt {
   public static final void toJsonElement(@NotNull Object $this$toJsonElement) {
      Intrinsics.checkNotNullParameter($this$toJsonElement, "<this>");
      KClassifiers.getStarProjectedType((KClassifier)Reflection.getOrCreateKotlinClass($this$toJsonElement.getClass()));
   }
}

and

import kotlin.Metadata;
import kotlin.jvm.internal.Reflection;
import kotlin.reflect.KClassifier;
import kotlin.reflect.full.KClassifiers;

@Metadata(
   mv = {1, 8, 0},
   k = 1,
   xi = 48,
   d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u0006\u0010\u0003\u001a\u00020\u0004¨\u0006\u0005"},
   d2 = {"Lca/solostudios/nyx/internal/util/Test;", "", "()V", "test", "", "nyx"}
)
public final class Test {
   public final void test() {
      KClassifiers.getStarProjectedType((KClassifier)Reflection.getOrCreateKotlinClass(this.getClass()));
   }
}

Interestingly, vineflower does not emit the kotlin.jvm.internal.Reflection or kotlin.reflect.KClassifier imports, however it does emit the kotlin.reflect.full.KClassifiers import.

@jaskarth jaskarth added Type: Bug Something isn't working Subsystem: Writing Anything concerning how expressions are written Priority: Medium Medium priority Subsystem: Plugins/Kotlin Anything specifically concerning the Kotlin plugin labels Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Medium Medium priority Subsystem: Plugins/Kotlin Anything specifically concerning the Kotlin plugin Subsystem: Writing Anything concerning how expressions are written Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants