-
-
Notifications
You must be signed in to change notification settings - Fork 823
Closed
Labels
Milestone
Description
Expected Behavior
Private property delegation operators are marked as used when they are used.
Observed Behavior
Property delegation operator by (getValue, setValue) has false positives for UnusedPrivateMember.
Steps to Reproduce
I've created a unit test that fits into UnusedPrivateMemberSpec that triggers the false positive. Looking through the other tests, the public property should be enough to be considered used.
it("Does not report used getValue, setValue") {
val code = """
class Test {
var delegated by "Hello"
}
private operator fun String.getValue(test: Test, prop: KProperty<*>): String {
return "working"
}
private operator fun String.setValue(test: Test, prop: KProperty<*>, value: String) {
error("setValue")
}
""".trimIndent()
assertThat(subject.compileAndLintWithContext(env, code)).hasSize(0)
}
Context
I originally wanted to create delegate methods for ThreadLocal scoped to within my current file so I could use it like a regular variable, but after updating detekt it's now being flagged as an unused member.
It is not being flagged in 1.5.1, b190e11
Bisect shows it was introduced here with the unused operator overload detection: 38c54c8
Your Environment
- Version of detekt used: 1.14.1, 782fb75
- Version of Gradle used (if applicable): gradlew in repo (Gradle 6.7-rc-2)
- Operating System and version: Artic Linux 5.8.10-artix1-1
Reactions are currently unavailable