Skip to content

Detekt 1.22.0-RC1 -> 1.22.0-RC2 breaks UnreachableCode #5435

Closed

Description

@jeffdcamp

After updating from Detekt 1.22.0-RC1 to 1.22.0-RC2 invalid UnreachableCode violations are showing

Expected Behavior

Code called from external libraries should not cause UnreachableCode

Observed Behavior

Any code called from an external library in an ?: operator causes UnreachableCode

Steps to Reproduce

Run ./gradlew detektDebug

Error:
Test.kt:13:9: This expression is unreachable code which should either be used or removed. [UnreachableCode]

Sample Code (Failing code on line 11, Workaround code on line 12)

package org.test

import androidx.core.net.toUri

class Test {
    fun testBug() {
        getLastPathSegment("test.mp4")
    }

    private fun getLastPathSegment(uriText: String) {
        val uri = uriText.toUri() // causes UnreachableCode.... code ref in core-ktx-1.5.0.jar: public inline fun String.toUri(): Uri = Uri.parse(this))
//        val uri = Uri.parse(uriText) // does NOT cause UnreachableCode (copied code from core-ktx-1.5.0.jar)
        val lastPath = uri.lastPathSegment ?: return
        println(lastPath)
    }
}

Your Environment

Detekt 1.2.2.0-RC2
Seen this same issue in many projects on different dev environments

Activity

  1. BraisGabin commented on Oct 23, 2022

    @BraisGabin
    Member

    I have two theories here:

  2. added this to the 1.22.0 milestone on Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions