-
-
Notifications
You must be signed in to change notification settings - Fork 767
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
Add SuspendFunWithCoroutineScopeReceiver Rule #4616
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice PR! :)
To make CI happy you need to run ./gradlew generateDocumentation
and commit the changes that it will add in the default-detekt-config
file.
...lin/io/gitlab/arturbosch/detekt/rules/coroutines/SuspendFunWithCoroutineScopeReceiverSpec.kt
Show resolved
Hide resolved
Ah, there is the default configuration. I've already searched for it :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the contribution!
I forgot the embedded Kotlin compiler provided by Gradle uses a different language API than the actual compiler executing the tests. So you can't use |
...lin/io/gitlab/arturbosch/detekt/rules/coroutines/SuspendFunWithCoroutineScopeReceiverSpec.kt
Outdated
Show resolved
Hide resolved
I just found this on the project I work: |
@BraisGabin Sure, added |
Codecov Report
@@ Coverage Diff @@
## main #4616 +/- ##
===========================================
+ Coverage 0 84.54% +84.54%
- Complexity 0 3381 +3381
===========================================
Files 0 483 +483
Lines 0 11242 +11242
Branches 0 2050 +2050
===========================================
+ Hits 0 9504 +9504
- Misses 0 698 +698
- Partials 0 1040 +1040
Continue to review full report at Codecov.
|
Oh, it seems that #4630 is making this PR to fail now. I suppose that they are just the indentation of |
Yeah, fixed it. |
@BraisGabin What about changing |
This is kind of a pain for sure. If we have enable by default we are testing the test code every time. And this task is slow. For that reason we don't have it enable by default. |
Co-authored-by: hfhbd <hfhbd@users.noreply.github.com>
@BraisGabin BTW are you sure about flagging lambdas too? In IntelliJ, only the function with the receiver is marked, but I don't know if this is a bug of IntelliJ... import kotlinx.coroutines.*
import kotlin.time.Duration.Companion.seconds
suspend fun main() {
coroutineScope {
receiver()
}
block {
launch {
}
}
}
suspend fun CoroutineScope.receiver(block: suspend CoroutineScope.() -> Unit) { // Ambiguous coroutineContext due to CoroutineScope receiver of suspend function
delay(1.seconds)
launch { // Ambiguous coroutineContext due to CoroutineScope receiver of suspend function
delay(1.seconds)
block()
}
}
suspend fun block(block: suspend CoroutineScope.() -> Unit) {
delay(1.seconds)
coroutineScope {
delay(1.seconds)
block()
}
} |
block {
launch { } // Which scope am I using the one from suspend or the receiver?
} I think that the issue is the same. But can you open an issue to intellij to confirm that is a missing part on their end? |
Sure. My concern about lambdas is its usage inside coroutine-core itself. |
Honestly, after reading https://youtrack.jetbrains.com/issue/KTIJ-12776 and https://youtrack.jetbrains.com/issue/KTIJ-13692/Ambiguous-calls-to-coroutineContext-should-be-reported, I still don't know, when we should mark the coroutine builder (suspend lambda with coroutinescope). |
We can wait to see what they say in the new issue. But for me the issue is the same. In the body of those lambdas is confusing what |
@BraisGabin Got an interesting answer. https://youtrack.jetbrains.com/issue/KT-52042/Clarifying-suspend-lambda-and-function-with-coroutineScope-as-pa#focus=Comments-27-6029021.0-0 |
Fixes #4587