Hello. Is there a way to check for instance of era...
# kotlin-native
r
Hello. Is there a way to check for instance of erased type in this case?
Copy code
fun mixedFrom(value: Any?) = when (value) {
    null                                            -> createPhpNull()
    is CPointer<zval>                               -> value
    else                                            -> value.toString().mixed
}
Copy code
error: cannot check for instance of erased type: CPointer<zval /* = _zval_struct */>
    is CPointer<zval>                                     -> value
s
Hello. No. As an alternative, in some cases it is possible to declare specialized functions instead, e.g.:
Copy code
fun mixedFrom(value: Nothing?) = createPhpNull()
fun mixedFrom(value: CPointer<zval>) = value
fun mixedFrom(value: Any?) = value.toString().mixed
r
Yes, I think about this workaround, but unfortunately it does not work if we have chain of
Any
arguments.
Copy code
fun put(key:Any, value:Any){
    val myMap:HashMap<Mixed, Mixed> = mutableMapOf()
    myMap.put(mixedFrom(key), mixedFrom(value))
}
Or I mistaken?
s
Yes, the workaround doesn’t work in this case. If you need to check the type dynamically, then the only option you have is to check that
value is CPointer<*>
.