Slackbot
06/16/2025, 3:25 PMYoussef Shoaib [MOD]
06/16/2025, 3:44 PMSimpleObjectProperty defined? I think there could be a way to pass-on the fact that Color may be nullableYoussef Shoaib [MOD]
06/16/2025, 3:47 PMSimpleObjectProperty<Nothing> and bad things happen. How does SimpleObjectProperty work? If one can provide e.g. a property reference, then you could use that to smuggle a platform type thru I thinkYoussef Shoaib [MOD]
06/16/2025, 3:49 PMSimpleObjectProperty spawns things from thin air, so things can always go wrong. If it was e.g. SimpleObjectProperty(SomeJavaFxClass::color), then I think it'll end up with a platform type and everything will work fineYoussef Shoaib [MOD]
06/16/2025, 3:54 PMYoussef Shoaib [MOD]
06/16/2025, 3:59 PMpublic operator fun <T> ObservableValue<T>.getValue(thisRef: Any?, property: KProperty<*>) = value // or getValue()Youssef Shoaib [MOD]
06/16/2025, 4:38 PMimport kotlin.reflect.KProperty
// This can exist in its own module, with explicit API turned off. It only needs to exist once
sealed interface TypeWrapperT {
companion object IMPL : TypeWrapperNothing
}
@Suppress("UNCHECKED_CAST")
public fun T platformType() = PlatformType.identity(TypeWrapper.IMPL as TypeWrapperT)
//////////////////////
class SimpleObjectPropertyT
public operator fun T SimpleObjectPropertyT.getValue(thisRef: Any?, property: KProperty*): T = TODO()
public operator fun T SimpleObjectPropertyT.setValue(thisRef: Any?, property: KProperty*, value: T) {
}
fun T SimpleObjectProperty(type: TypeWrapperT): SimpleObjectPropertyT = TODO()
fun example() {
val foo by SimpleObjectProperty(platformTypeString()) // IntelliJ shows type as String!
foo.length // compiles fine!
foo!! // no warnings!
}
import org.jetbrains.annotations.NotNull;
public class PlatformType {
@NotNull
public static T TypeWrapperT identity(TypeWrapperT type) {
return type;
}
}
This creates a platform type from a user-provided normal type. The key is that the user needs to use platformType to specify the type. You can also have the SimpleObjectProperty automatically have a platform type by explicitly defining (with explicit API turned off):
fun T SimpleObjectProperty() = SimpleObjectProperty(platformTypeT())
fun example() {
val foo by SimpleObjectPropertyString() // IntelliJ shows type as String!
foo.length // compiles fine!
foo!! // no warnings!
}
so every platform type introduction will need some explicit-API-prohibited method, but after that type has been smuggled, it can be used wherever you'd like just fine.
Is there error suppression for explicit API?Youssef Shoaib [MOD]
06/16/2025, 5:23 PM@Suppress("UNCHECKED_CAST")
private fun <T> SimpleObjectProperty<*>.asType(type: TypeWrapper<T>) = this as SimpleObjectProperty<T>
public fun <T> SimpleObjectProperty<T>.toPlatformType() = asType(platformType<T>())
fun example() {
val foo by SimpleObjectProperty<String>().toPlatformType() // IntelliJ shows type as String!
foo.length // compiles fine!
foo!! // no warnings!
}
Make such a toPlatformType for every interface that's used. It's annoying, but it's only a one-time costYoussef Shoaib [MOD]
06/16/2025, 5:35 PMObservableValue was converted to a platform type ObservableValue<T!>, then the lambda should have the right typeYoussef Shoaib [MOD]
06/16/2025, 5:47 PMPlatformType class only is for your private implementation to easily create `TypeWrapper`s of platform types. You can make that private, or write it once in a library. The actual cost per type is this pattern:
@Suppress("UNCHECKED_CAST")
private fun T SimpleObjectProperty*.asType(type: TypeWrapperT) = this as SimpleObjectPropertyT
public fun T SimpleObjectPropertyT.toPlatformType() = asType(platformTypeT())
Which can probably be generated automatically. The point then is the user chooses to use a platform type by writing toPlatformType, and call resolution takes care of finding the right one. You need 2 such methods for every type you want to support, but subtypes are fine btw, except that they'll be cast to whatever supertype has toPlatformType defined on it.
So you'd define it for ObservableValue, WriteableValue, etc, and the user just needs to use it when possible.