Kotlin / kotlinx-kover

Apache License 2.0
1.28k stars 48 forks source link

Why some data class constructors show an missed branches? #420

Open klys-equinix opened 11 months ago

klys-equinix commented 11 months ago
Screenshot 2023-06-30 at 09 24 47
shanshin commented 11 months ago

Hi, to understand the causes of the problem, we need additional information.

May you provide a compiled class-file for DrawCapOptionWithPrice class? And give an example of the original source code of this class. Which version of the compiler was used?

klys-equinix commented 11 months ago

Source code:

data class DrawCapOptionWithPrice(
    val rating: BandRating,
    val cost: Cost,
    val top: Boolean = false,
)

Class attached DrawCapOptionWithPrice.class.zip

Compiler: Azul Zulu SDK 17

Kotlin: 1.7.22

shanshin commented 11 months ago

Thanks! Also XML report would be helpful

klys-equinix commented 11 months ago
<class name="com/example/scx/common/DrawCapOptionWithPrice" sourcefilename="CommonValueObjects.kt">
<method name="&lt;init&gt;" desc="(Lcom/example/scx/common/BandRating;Lcom/example/scx/common/Cost;Z)V">
<counter type="INSTRUCTION" missed="0" covered="28"/>
<counter type="BRANCH" missed="1" covered="1"/>
<counter type="LINE" missed="0" covered="4"/>
</method>
klys-equinix commented 11 months ago

Also, this is not an exception. It happens to many data classes. It seems to affect those data classes that have extension methods.

shanshin commented 11 months ago

@losiu97, is this for Kover version 0.7.2?

klys-equinix commented 11 months ago

yes

zuevmaxim commented 11 months ago

@klys-equinix Unfortunately, I cannot reproduce your issue on my examples. Could you please share some more code? If your project is open-source, please share a link. Alternatively, it would be nice to have a small reproducer project. If it is impossible to reproduce with a small project, could you please share an example of an extension function for the class? (with bytecode preferably).

klys-equinix commented 11 months ago

I tried reproducing this in a reproducer project, but i have not been able to see the same problems. I am at a loss why it happens in our main project. Unfortunetely, it would be hard to share the bytecode from that