Skip to content

Kotlin default arguments should not be filtered out #773

@Godin

Description

@Godin

Because they can be arbitrary expressions and so can contain branches:

object KotlinDefaultArgumentsTarget {

    private fun f(a: Int, b: Int = if (a > 0) 1 else 2) {
    }

    @JvmStatic
    fun main(args: Array<String>) {
    }

}

which are currently not shown

$ kotlinc KotlinDefaultArgumentsTarget.kt

$ java -javaagent:jacoco-0.8.2/lib/jacocoagent.jar \
    -cp .:kotlin-runtime.jar \
    KotlinDefaultArgumentsTarget

$ java -jar jacoco-0.8.2/lib/jacococli.jar \
    report jacoco.exec \
    --classfiles KotlinDefaultArgumentsTarget.class \
    --sourcefiles . \
    --html report

report

because this line associated with synthetic method:

  static void f$default(KotlinDefaultArgumentsTarget, int, int, int, java.lang.Object);
    descriptor: (LKotlinDefaultArgumentsTarget;IIILjava/lang/Object;)V
    flags: ACC_STATIC, ACC_BRIDGE, ACC_SYNTHETIC
    Code:
      stack=3, locals=5, args_size=5
         0: iload_3
         1: iconst_2
         2: iand
         3: ifeq          16
         6: iload_1
         7: ifle          14
        10: iconst_1
        11: goto          15
        14: iconst_2
        15: istore_2
        16: aload_0
        17: iload_1
        18: iload_2
        19: invokespecial #15                 // Method f:(II)V
        22: return
      LineNumberTable:
        line 3: 6

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions