This message was deleted.
# language-proposals
s
This message was deleted.
y
How is
SimpleObjectProperty
defined? I think there could be a way to pass-on the fact that Color may be nullable
I mean, as far as I can tell, someone can just pass
SimpleObjectProperty<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 think
Your issue is that
SimpleObjectProperty
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 fine
Ohhhhhh okay that makes more sense
What happens if you just write:
Copy code
public operator fun <T> ObservableValue<T>.getValue(thisRef: Any?, property: KProperty<*>) = value // or getValue()
This is a little convoluted, so bear with me:
Copy code
import 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!
}
Copy code
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):
Copy code
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?
Slightly better idea:
Copy code
@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 cost
For the binding one, as long as
ObservableValue
was converted to a platform type
ObservableValue<T!>
, then the lambda should have the right type
PlatformType
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:
Copy code
@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.