Skip to content

KotlinDefaultMethodsFilter should filter compatibility methods#1905

Merged
Godin merged 5 commits into
jacoco:masterfrom
Godin:kotlin_jvm-default
Oct 29, 2025
Merged

KotlinDefaultMethodsFilter should filter compatibility methods#1905
Godin merged 5 commits into
jacoco:masterfrom
Godin:kotlin_jvm-default

Conversation

@Godin

@Godin Godin commented Oct 28, 2025

Copy link
Copy Markdown
Member

See https://kotlinlang.org/docs/whatsnew22.html#changes-to-default-method-generation-for-interface-functions


For Example.kt

interface I {
  fun m() {
    print("default")
  }
}

class C : I { // line 7
}

Kotlin compiler version 2.1.0 produces

javap -v -p I.class

{
  public abstract void m();
    descriptor: ()V
    flags: (0x0401) ACC_PUBLIC, ACC_ABSTRACT
}

javap -v -p I\$DefaultImpls.class

  public static void m(I);
    descriptor: (LI;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=1, args_size=1
         0: ldc           #9                  // String default
         2: getstatic     #15                 // Field java/lang/System.out:Ljava/io/PrintStream;
         5: swap
         6: invokevirtual #21                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
         9: return
      LineNumberTable:
        line 3: 0
        line 4: 9

javap -v -p C.class

  public C();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #10                 // Method java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 7: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LC;

  public void m();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokestatic  #18                 // Method I$DefaultImpls.m:(LI;)V
         4: return
      LineNumberTable:
        line 7: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LC;

Kotlin compiler versions from 2.2.0 to 2.2.10 produce

javap -v -p I.class

  public default void m();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         0: ldc           #8                  // String default
         2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
         5: swap
         6: invokevirtual #20                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
         9: return
      LineNumberTable:
        line 3: 0
        line 4: 9
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      10     0  this   LI;

  public static void access$m$jd(I);
    descriptor: (LI;)V
    flags: (0x1009) ACC_PUBLIC, ACC_STATIC, ACC_SYNTHETIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #26                 // InterfaceMethod m:()V
         4: return
      LineNumberTable:
        line 1: 1
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0 $this   LI;

javap -v -p I\$DefaultImpls.class

  public static void m(I);
    descriptor: (LI;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokestatic  #13                 // InterfaceMethod I.access$m$jd:(LI;)V
         4: return
      LineNumberTable:
        line 2: 0
        line 4: 4
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0 $this   LI;
    Deprecated: true
    RuntimeVisibleAnnotations:
      0: #7()
        java.lang.Deprecated
    RuntimeInvisibleParameterAnnotations:
      parameter 0:
        0: #8()
          org.jetbrains.annotations.NotNull

javap -v -p C.class

  public void m();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #15                 // InterfaceMethod I.m:()V
         4: return
      LineNumberTable:
        line 7: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LC;

Methods I$DefaultImpls.m and C.m should be filtered out.


Kotlin compiler version 2.2.20 produces

javap -v -p I.class

  public default void m();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=1, args_size=1
         0: ldc           #8                  // String default
         2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
         5: swap
         6: invokevirtual #20                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
         9: return
      LineNumberTable:
        line 3: 0
        line 4: 9
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0      10     0  this   LI;

  public static void access$m$jd(I);
    descriptor: (LI;)V
    flags: (0x1009) ACC_PUBLIC, ACC_STATIC, ACC_SYNTHETIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #26                 // InterfaceMethod m:()V
         4: return
      LineNumberTable:
        line 1: 1
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0 $this   LI;

javap -v -p I\$DefaultImpls.class

  public static void m(I);
    descriptor: (LI;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokestatic  #13                 // InterfaceMethod I.access$m$jd:(LI;)V
         4: return
      LineNumberTable:
        line 2: 0
        line 4: 4
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0 $this   LI;
    Deprecated: true
    RuntimeVisibleAnnotations:
      0: #7()
        java.lang.Deprecated
    RuntimeInvisibleParameterAnnotations:
      parameter 0:
        0: #8()
          org.jetbrains.annotations.NotNull

javap -v -p C.class

  public void m();
    descriptor: ()V
    flags: (0x0041) ACC_PUBLIC, ACC_BRIDGE
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #15                 // InterfaceMethod I.m:()V
         4: return
      LineNumberTable:
        line 7: 0
      LocalVariableTable:
        Start  Length  Slot  Name   Signature
            0       5     0  this   LC;

Method I$DefaultImpls.m should be filtered.


https://groups.google.com/g/jacoco/c/QpoRB1Dn2BI/m/Rsa3N1GKAgAJ

@Godin Godin self-assigned this Jun 27, 2025
@Godin Godin added this to Filtering Jun 27, 2025
@github-project-automation github-project-automation Bot moved this to Awaiting triage in Filtering Jun 27, 2025
@Godin Godin moved this from Awaiting triage to To Do in Filtering Jun 27, 2025
@Godin

Godin commented Jul 28, 2025

Copy link
Copy Markdown
Member Author

@qwwdfsad similarly to #1752, #1557 and #1426
in this case compiler-generated non ACC_SYNTHETIC method
C.m has line number of class declaration line
I$DefaultImpls.m has line numbers of non compiler-generated I.m method
which according to https://youtrack.jetbrains.com/issue/KT-74091/K2-JvmOverloads-produced-overloads-have-generated-line-number-table

violates our rule about not having line numbers for compiler-produced "synthetic" (not ACC_SYNTHETIC) bodies

@Godin Godin changed the title Filter compatibility bridges generated by Kotlin 2.2.0 for functions defined in interfaces Filter compatibility bridges generated by Kotlin 2.2.0 - 2.2.10 for functions defined in interfaces Oct 28, 2025
@Godin Godin changed the title Filter compatibility bridges generated by Kotlin 2.2.0 - 2.2.10 for functions defined in interfaces Filter compatibility bridges generated by Kotlin 2.2.0 for functions defined in interfaces Oct 28, 2025
@Godin Godin added this to the 0.8.15 milestone Oct 28, 2025
@Godin Godin moved this from To Do to In Progress in Filtering Oct 28, 2025
@Godin Godin changed the title Filter compatibility bridges generated by Kotlin 2.2.0 for functions defined in interfaces KotlinDefaultMethodsFilter should filter compatibility methods Oct 28, 2025
@Godin Godin requested a review from leveretka October 28, 2025 21:25
@Godin Godin enabled auto-merge (squash) October 29, 2025 08:56
@Godin Godin merged commit e50e23b into jacoco:master Oct 29, 2025
36 checks passed
@Godin Godin deleted the kotlin_jvm-default branch October 29, 2025 09:53
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Filtering Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants