-
-
Notifications
You must be signed in to change notification settings - Fork 784
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
Fixes for Kotlin 1.6.0-M1 #4139
Conversation
Using org.jetbrains.kotlin.utils.addToStdlib.safeAs caused type inference failures in Kotlin 1.6.0-M1
Required in progressive mode on Kotlin 1.6.0-M1
Codecov Report
@@ Coverage Diff @@
## main #4139 +/- ##
=========================================
Coverage 83.45% 83.45%
Complexity 3185 3185
=========================================
Files 463 463
Lines 9095 9095
Branches 1768 1768
=========================================
Hits 7590 7590
Misses 571 571
Partials 934 934
Continue to review full report at Codecov.
|
} | ||
exitProcess(result.exitCode()) |
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.
Why? This doesn't seem right. If we are in the case of HandledArgumentViolation
we want to exit the process with the correct exitCode. Right?
I imagine that this is because of the exhaustive enums. But I think that instead of else
that doesn't give any information about which other cases go there we could use: null -> Unit
or null -> { /* no-op */ }
. I prefer the first one because with the second I always have a bad time: Does this case do nothing or does it return a lambda that does nothing?
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.
Good catch. This is indeed a miss from my side about the behavioral change.
@@ -37,7 +37,7 @@ fun getIntValueForPsiElement(element: PsiElement): Int? { | |||
|
|||
fun KtClass.companionObject() = this.companionObjects.singleOrNull { it.isCompanion() } | |||
|
|||
inline fun <reified T : Any> Any.safeAs(): T? = this as? T | |||
inline fun <reified T : Any> Any?.safeAs(): T? = this as? T |
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.
I imagine that you are adding this ?
to match what org.jetbrains.kotlin.utils.addToStdlib.safeAs
did, right? If it's that I'm fine. But I think that an extension function that when receives null
always return null
shouldn't handle that case. That responsability should be handled by the caller.
😂 I didn't realised that this was already merged |
@BraisGabin thanks for your feedback, I've raised #4143 to address it. |
* Reverse behaviour change introduced in #4139 https://github.com/detekt/detekt/pull/4139/files#r719991365 * Handle nullability at call site https://github.com/detekt/detekt/pull/4139/files#r719992612
Fixing a couple of issues identified with a test build using Kotlin 1.6.0-M1