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:
committed by
Alexander Udalov
parent
b1e82c78da
commit
05f6ed40f1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user