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

False positive UnusedPrivateMember for getValue, setValue operator functions #3128

Closed
rlewismd opened this issue Oct 5, 2020 · 0 comments · Fixed by #3139
Closed

False positive UnusedPrivateMember for getValue, setValue operator functions #3128

rlewismd opened this issue Oct 5, 2020 · 0 comments · Fixed by #3139

Comments

@rlewismd
Copy link

rlewismd commented Oct 5, 2020

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants