Don't generate setters for trivial private property setters

This change will prevent the compiler for generating Java bytecode for
private property setters that are trivial.

Since Kotlin uses direct field access for private properties, it will result
in the private setter never been used and since it cannot be accessed by any
other class without reflection, the setter cannot be covered by code
coverage tools.

See https://youtrack.jetbrains.com/issue/KT-20344 for the related YouTrack
issue.
This commit is contained in:
Fabian Mastenbroek
2018-07-19 13:45:50 +02:00
committed by Alexander Udalov
parent b1e82c78da
commit 05f6ed40f1
3 changed files with 18 additions and 5 deletions
@@ -210,6 +210,12 @@ public class PropertyCodegen {
return !isDefaultAccessor;
}
// Non-private properties with private setter should not be generated for trivial properties
// as the class will use direct field access instead
if (accessor != null && accessor.isSetter() && Visibilities.isPrivate(descriptor.getSetter().getVisibility())) {
return !isDefaultAccessor;
}
return true;
}