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

Investigate why Kotlin K2 compiler produces line numbers in the enums getEntries method #1557

Open
Godin opened this issue Dec 22, 2023 · 2 comments

Comments

@Godin
Copy link
Member

Godin commented Dec 22, 2023

Currently execution of

mvn \
  -Dkotlin.version=2.0.0-Beta2 \
  -Dbytecode.version=8 \
  clean package

leads to

Failed tests:
  KotlinWhenExpressionTest>ValidationTestBase.all_missed_instructions_should_have_line_number:142 sum of missed instructions of all lines should be equal to missed instructions of file expected:<4> but was:<3>

which is because for

enum class Example

Kotlin 2.0.0-Beta2 compiler produces

  public static kotlin.enums.EnumEntries<Example> getEntries();
    descriptor: ()Lkotlin/enums/EnumEntries;
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=0, args_size=0
         0: getstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
         3: areturn
      LineNumberTable:
        line 1: 3
    Signature: #38                          // ()Lkotlin/enums/EnumEntries<LExample;>;
    RuntimeInvisibleAnnotations:
      0: #39()
        org.jetbrains.annotations.NotNull

whereas Kotlin 1.9.22 compiler produces

  public static kotlin.enums.EnumEntries<Example> getEntries();
    descriptor: ()Lkotlin/enums/EnumEntries;
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=0, args_size=0
         0: getstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
         3: areturn
    Signature: #38                          // ()Lkotlin/enums/EnumEntries<LExample;>;
    RuntimeInvisibleAnnotations:
      0: #39()
        org.jetbrains.annotations.NotNull

Bisection of changes in Kotlin compiler pointed me to JetBrains/kotlin@5fb3800 which merely changes the language version, so either I made a mistake during bisection, or bytecode generation depends on the language version. I suspect the second because execution of Kotlin 1.9.22 compiler with option -language-version 2.0 produces the same result as the execution of Kotlin 2.0.0-Beta2 compiler.

@qwwdfsad could you please have a look and advise whether this change is intentional and we need to filter out getEntries methods in enums similarly to filtering valueOf and values methods, or this is an unintentionally overlooked change in the compiler?

@Godin
Copy link
Member Author

Godin commented Jan 29, 2024

The same still happens with Kotlin 2.0.0-Beta3 compiler.

@Godin
Copy link
Member Author

Godin commented Mar 26, 2024

@qwwdfsad FWIW the same still happens with Kotlin 2.0.0-Beta5 compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant