I notice there are several places where library code have difficulties using definitely non-nullable types:
|
// FIXME: The cast is a workaround for https://youtrack.jetbrains.com/issue/KT-59493, it can be removed with KT v1.9.20 |
|
// FIXME: The cast is a workaround for https://youtrack.jetbrains.com/issue/KT-59493, it can be removed with KT v1.9.20 |
|
// FIXME: The cast is a workaround for https://youtrack.jetbrains.com/issue/KT-59493 and https://youtrack.jetbrains.com/issue/KT-62543 |
After checking referenced kotlin issue, it seems it is not an actual root of this problem. Actual referenced issue should be this one.
Looking at this second issue right now my guess it will stay in backlog for a very long time. And it is definitely not fixed in 1.9.20 and even in 2.0.21 (I checked).
I think this could actually be fixed internally just by using nullable type bounds instead of definitely non-nullable type on one method.
Instead of
@JvmName("nullableValidatableOfProperty")
public fun <T : Any?, V> Validatable<T>.validatableOf(getter: KProperty1<T & Any, V>): Validatable<V?> {
return Validatable(unwrap()?.let { getter.get(it) }, getter.name, this)
}
we can do
@JvmName("nullableValidatableOfProperty")
public fun <T : Any, V> Validatable<T?>.validatableOf(getter: KProperty1<T, V>): Validatable<V?> {
return Validatable(unwrap()?.let { getter.get(it) }, getter.name, this)
}
I already tried this change and everything seems to build/run/work without any problem and with KProperty1 casts removed.
After checking kotlin documentation I feel there is no need for definitely non-nullable type here. Some quotes:
The most common use case for declaring definitely non-nullable types is when you want to override a Java method that contains @NotNull as an argument. For example, consider the load() method
When working only with Kotlin, it's unlikely that you will need to declare definitely non-nullable types explicitly because Kotlin's type inference takes care of this for you.
I notice there are several places where library code have difficulties using definitely non-nullable types:
akkurate/akkurate-core/src/commonTest/kotlin/dev/nesk/akkurate/validatables/ValidatableTest.kt
Line 106 in 492b847
akkurate/akkurate-core/src/commonTest/kotlin/dev/nesk/akkurate/validatables/ValidatableTest.kt
Line 118 in 492b847
akkurate/akkurate-ksp-plugin/src/main/kotlin/dev/nesk/akkurate/ksp/ValidateAnnotationProcessor.kt
Line 229 in 492b847
After checking referenced kotlin issue, it seems it is not an actual root of this problem. Actual referenced issue should be this one.
Looking at this second issue right now my guess it will stay in backlog for a very long time. And it is definitely not fixed in 1.9.20 and even in 2.0.21 (I checked).
I think this could actually be fixed internally just by using nullable type bounds instead of definitely non-nullable type on one method.
Instead of
we can do
I already tried this change and everything seems to build/run/work without any problem and with
KProperty1casts removed.After checking kotlin documentation I feel there is no need for definitely non-nullable type here. Some quotes: