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

UnreachableCode: false positive when use error from Coil #4250

Closed
osipxd opened this issue Nov 9, 2021 · 4 comments · Fixed by #4259
Closed

UnreachableCode: false positive when use error from Coil #4250

osipxd opened this issue Nov 9, 2021 · 4 comments · Fixed by #4259

Comments

@osipxd
Copy link
Contributor

osipxd commented Nov 9, 2021

Observed Behavior

imageView.load(imageUrl) {
    placeholder(R.drawable.image_placeholder)
    error(R.drawable.image_error)       // This is not Kotlin's error function
    fallback(R.drawable.image_fallback) // UnreachableCode reported here, but this code is reachable
}

Context

We use Coil library for image loading and there are methods called error.
It looks like detekt considers all functions with the name error as Kotlin's error function.

Steps to reproduce

A project to reproduce the issue

Your Environment

  • Version of detekt used: 1.18.0
@BraisGabin
Copy link
Member

I just created a fast Unit test and I can't reproduce your behaviour:

        it("Does not report unreachable code after custom error function") {
            val code = """
                fun error(a: Int) {
                    println(a)
                }

                fun test(): Int {
                    error(5)
                    return 0
                }
            """
            assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
        }

Could you provide a project to reproduce this issue?

@osipxd
Copy link
Contributor Author

osipxd commented Nov 9, 2021

Yes, I'm trying to create a simple reproducer

@osipxd
Copy link
Contributor Author

osipxd commented Nov 9, 2021

Here is the simple reproducer project.

This is the commit with code related to the issue, and this is the failing task on CI.

@3flex
Copy link
Member

3flex commented Nov 10, 2021

Looking at the CI failure this is likely a duplicate of #4253

load, placeholder and fallback from Coil aren't resolved. I expect error wouldn't have been either, except this doesn't show as a failure in CI, because the compiler is instead resolving Kotlin's built in error function.

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