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

Skip coverage for methods generated for inline classes #973

Closed
mkrussel77 opened this issue Nov 12, 2019 · 5 comments · Fixed by #1475
Closed

Skip coverage for methods generated for inline classes #973

mkrussel77 opened this issue Nov 12, 2019 · 5 comments · Fixed by #1475

Comments

@mkrussel77
Copy link

THIS IS A BUG TRACKER ONLY. FOR QUESTIONS PLEASE CHECK FAQ OR USE FORUM:

http://www.jacoco.org/jacoco/trunk/doc/faq.html

https://groups.google.com/forum/?fromgroups=#!forum/jacoco

Please understand that
ISSUES WITHOUT FOLLOWING INFORMATION WILL BE CLOSED WITHOUT COMMENTS!
Thank you for filling feature request!

Scenario

  • JaCoCo version: (from right bottom corner of JaCoCo report) 0.8.5.201910111838
  • Operating system: Mac OS
  • Tool integration: Maven / Ant / CLI / API (for others please report to respective project) Gradle
  • Description of your use case: (detailed description or executable reproducer, e.g. GitHub repo)

Kotlin generates several methods for inline classes similar to how it does for data classes.

  • equals()
  • hashcode()
  • toString()
  • getter for wrapped value

Would like inline classes to behave like data classes. I know inline classes are experimental so adding it at this point might cause breakage in the future.

Current Behaviour

All of these methods are reported as unused

Wanted Behaviour

The methods to not be reported as unused

Possible Workarounds

Use data classes instead of inline classes

@Godin
Copy link
Member

Godin commented Nov 20, 2019

For methods generated in data classes Kotlin compiler does not generate line numbers - see #689

Whereas seems that for inline classes Kotlin compiler 1.3.60 generates methods that always have line number 1 - for example compilation of following Example.kt (kotlinc Example.kt)

data class DataClassExample( // line 1
  val p: String
)

inline class InlineClassExample( // line 5
  val p: String
)

results in following methods (javap -v -p InlineClassExample.class)

  public java.lang.String toString();
    descriptor: ()Ljava/lang/String;
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: getfield      #11                 // Field p:Ljava/lang/String;
         4: invokestatic  #72                 // Method "toString-impl":(Ljava/lang/String;)Ljava/lang/String;
         7: areturn
      LineNumberTable:
        line 1: 0

  public int hashCode();
    descriptor: ()I
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: getfield      #11                 // Field p:Ljava/lang/String;
         4: invokestatic  #74                 // Method "hashCode-impl":(Ljava/lang/String;)I
         7: ireturn
      LineNumberTable:
        line 1: 0

  public boolean equals(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Z
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=2, locals=2, args_size=2
         0: aload_0
         1: getfield      #11                 // Field p:Ljava/lang/String;
         4: aload_1
         5: invokestatic  #78                 // Method "equals-impl":(Ljava/lang/String;Ljava/lang/Object;)Z
         8: ireturn
      LineNumberTable:
        line 1: 0

which IMO does not make any sense, looks like bug in Kotlin compiler (CC @goodwinnk) and leads to the fact that JaCoCo does not filter these methods similarly to ones in data classes and so they show up in report.

Thus @mkrussel77 could you please report this to developers of Kotlin compiler in their issue tracker with cross-reference to/from this ticket?

@Godin
Copy link
Member

Godin commented Nov 20, 2019

Moreover following example demonstrates that this affects not only JaCoCo, but also debugger:

Foo.java

public class Foo {
	public static void main(String[] args) {
		InlineClass c = BarKt.create().get(0);
		c.hashCode();  // line 4
	}
}

Bar.kt

fun create(): List<InlineClass> = arrayListOf(InlineClass(""))  // line 1

inline class InlineClass(
        val value: String
)

after step from breakpoint on line 4 of Foo.java, debugger will show line 1 of Bar.kt which is incorrect and misleading.

@Godin Godin added the feedback pending Further information is requested label Dec 2, 2019
@Godin
Copy link
Member

Godin commented Dec 13, 2019

@mkrussel77 have you reported this to the developers of Kotlin compiler in their issue tracker?

@mkrussel77
Copy link
Author

I created ticket https://youtrack.jetbrains.com/issue/KT-35553

@Godin
Copy link
Member

Godin commented Dec 18, 2019

@mkrussel77 thank you! 👍 ❤️

@Godin Godin self-assigned this Apr 17, 2023
@Godin Godin added this to Awaiting triage in Filtering via automation Apr 17, 2023
@Godin Godin added language: Kotlin and removed feedback pending Further information is requested labels May 9, 2023
@Godin Godin moved this from Awaiting triage to To Do in Filtering May 6, 2024
Filtering automation moved this from To Do to Done May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Filtering
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants