Add SuspendFunWithCoroutineScopeReceiver Rule#4616
Add SuspendFunWithCoroutineScopeReceiver Rule#4616cortinico merged 1 commit intodetekt:mainfrom hfhbd:main
Conversation
BraisGabin
left a comment
There was a problem hiding this comment.
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.
|
Ah, there is the default configuration. I've already searched for it :D |
BraisGabin
left a comment
There was a problem hiding this comment.
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 |
|
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