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

RedundantSuspendModifier false-positives with extension functions #7223

Open
sschuberth opened this issue Apr 24, 2024 · 3 comments
Open

RedundantSuspendModifier false-positives with extension functions #7223

sschuberth opened this issue Apr 24, 2024 · 3 comments

Comments

@sschuberth
Copy link
Contributor

Expected Behavior

RedundantSuspendModifier should not complain for suspend functions that call suspend functions

Observed Behavior

RedundantSuspendModifier is reported for this code:

suspend fun deleteForOrganization(organizationId: Long, name: String) {
    db.dbQuery {
        infrastructureServiceRepository.deleteForOrganizationAndName(organizationId, name)
    }
}

with

suspend fun <T> Database.dbQuery(
    transactionIsolation: Int = transactionManager.defaultIsolationLevel,
    readOnly: Boolean = transactionManager.defaultReadOnly,
    block: () -> T
): T =
    dbQueryCatching(transactionIsolation, readOnly, block).getOrThrow()

Steps to Reproduce

Run Detekt with type resolution (./gradlew detektMain) on https://github.com/eclipse-apoapsis/ort-server/blob/main/services/infrastructure/src/main/kotlin/InfrastructureServiceService.kt

Context

n/a

Your Environment

  • Version of detekt used: 1.23.6
  • Version of Gradle used (if applicable): 8.7
  • Gradle scan link (add --scan option when running the gradle task): n/a
  • Operating System and version: Fedora Linus 39
  • Link to your project (if it's a public repository): https://github.com/eclipse-apoapsis/ort-server
@atulgpt
Copy link
Contributor

atulgpt commented Apr 24, 2024

I have added TC for

@Test
fun `does not report when suspend function is called in extension method`() {
    val code = """
        import kotlinx.coroutines.delay
        suspend fun foo() { delay(1000) }
        suspend fun String.bar() {
            foo()
        }
        suspend fun  String.baz() = foo()
    """.trimIndent()
    assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
}

And extension method detection working fine. Are you running detect tasks with the correct type resolution?

@sschuberth
Copy link
Contributor Author

Are you running detect tasks with the correct type resolution?

What do you mean by "correct"? But yes, I'm using type resolution in general, i.e. I run the detektMain task instead of the detekt task.

@atulgpt
Copy link
Contributor

atulgpt commented Apr 24, 2024

Hi @sschuberth it could detekt is unable to determine dbQueryCatching(transactionIsolation, readOnly, block) as suspend fun. Or can you give complete self-reproducible example where false +ve is coming

@sschuberth sschuberth changed the title RedundantSuspendModifier false-posiotives with extension functions RedundantSuspendModifier false-positives with extension functions Apr 24, 2024
sschuberth added a commit to doubleopen-project/ort-server that referenced this issue Apr 26, 2024
This has too many false-positives, see [1].

[1]: detekt/detekt#7223

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit to doubleopen-project/ort-server that referenced this issue Apr 26, 2024
This has too many false-positives, see [1].

[1]: detekt/detekt#7223

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit to doubleopen-project/ort-server that referenced this issue Apr 26, 2024
This has too many false-positives, see [1].

[1]: detekt/detekt#7223

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit to doubleopen-project/ort-server that referenced this issue Apr 26, 2024
This has too many false-positives, see [1].

[1]: detekt/detekt#7223

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit to doubleopen-project/ort-server that referenced this issue Apr 26, 2024
This has too many false-positives, see [1].

[1]: detekt/detekt#7223

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
sschuberth added a commit to doubleopen-project/ort-server that referenced this issue Apr 28, 2024
This has too many false-positives, see [1].

[1]: detekt/detekt#7223

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
github-merge-queue bot pushed a commit to eclipse-apoapsis/ort-server that referenced this issue Apr 28, 2024
This has too many false-positives, see [1].

[1]: detekt/detekt#7223

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants