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

UnusedPrivateMember - [invoke]: False positive: Used by public member function #4435

Closed
hfhbd opened this issue Jan 2, 2022 · 6 comments · Fixed by #5717
Closed

UnusedPrivateMember - [invoke]: False positive: Used by public member function #4435

hfhbd opened this issue Jan 2, 2022 · 6 comments · Fixed by #5717

Comments

@hfhbd
Copy link
Contributor

hfhbd commented Jan 2, 2022

Expected Behavior

no issue

Observed Behavior

UnusedPrivateMember - [invoke] at /Users/philipwedemann/invokeFalsePositive/src/main/kotlin/Test.kt:2:5

Steps to Reproduce

./gradlew detekt

object Test {
    private operator fun invoke(i: Int): Int = i

    fun answer() = Test(1)
}

val answer = Test.answer()

See also the attached reproducer project

Context

I adopt the code style from kotlinx.coroutines, which uses this constructor like function to emulate a constructor for an interface:

interface MutableStateFlow { }
fun MutableStateFlow(initValue: t) { }

Using this code style for the invoke function and combine it with objects results into some kind of namespaces.

Your Environment

@hfhbd hfhbd added the bug label Jan 2, 2022
@BraisGabin
Copy link
Member

Related with #4242.

@BraisGabin
Copy link
Member

BraisGabin commented Jan 3, 2022

@hfhbd your issue I think that it will be solved by #4441 because you aren't using type solving. But I'll keep this open because we have the same issue with type solving too.

I reproduced that issue with this test:

        it("does not report used invoke operator - #4435") {
            val code = """
                object Test {
                    private operator fun invoke(i: Int): Int = i
                
                    fun answer() = Test(1)
                }

                val answer = Test.answer()
            """
            assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
        }

@github-actions
Copy link

github-actions bot commented Apr 4, 2022

This issue is stale because it has been open 90 days with no activity. Please comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Apr 4, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@chao2zhang
Copy link
Member

@BraisGabin Is the stance that we should acknowledge such degradation of UnusedPrivateMember with type resolution?

@atulgpt
Copy link
Contributor

atulgpt commented Jan 21, 2023

Hi @BraisGabin, this is also blocked for my project. I have created a PR for the fix at #5717

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.

4 participants