Skip to content

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

@Godin

Description

@Godin

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?

Metadata

Metadata

Assignees

Labels

language: KotlinTickets about Kotlin language support

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions