Annotating auto-generated methods?

Mutation testing frameworks like PIT want to modify code that are user authored, to inject bugs and then see if they’re caught by unit tests.

As you can see:

improve kotlin support · Issue #260 · hcoles/pitest · GitHub

They are attempting to come up with heuristics to identify methods that cannot possibly contain bugs because they are auto-generated by the Kotlin compiler (and we assume, of course, that the JetBrains team do not create bugs in such methods ;)).

It seems like the cleanest solution would be to introduce a new annotation and have the Kotlin compiler attach it to methods that are fully auto generated like data class methods, auto-generated getters/setters, auto-generated constructors and so on.

How hard would that be? I’m assuming not that hard.

This would be of benefit to other bytecode based tooling such as line coverage systems as well.

I think this would basically be a ‘synthetic’ annotation, but would be applied more liberally than the synthetic attribute.

shouldn’t the synthetic attribute be enough?

As an example

data class User(val name: String, val age: Int)

Will generate getName, getAge, component1, component2 and copy methods none of which are currently marked as synthetic.

Some-one more knowledgeable than me will need to explain why they can’t be marked as synthetic, but I remember reading through a Scala compiler thread where methods were marked as synthetic then the change reverted as it interacted badly with Java tooling which hid the methods from view.

You’re right, synthetic methods are invisible from java.

Are there any plans to implement this? or maybe a viable alternative to it?

Corresponding issue https://youtrack.jetbrains.com/issue/KT-13102 you can vote and follow.