Multiplatform expect/actual, typealias, and extension functions


#1

I’m still verifying that I’m not missing something in the test I’m doing, but here’s what I’m trying to do. I’m using a typealias to implement the ‘actual’ side of an ‘expect’ pair, for jvm and native (ios). The native side has a very similar type signature, but not exact. I was thinking of using extension functions to sort that out, but the ‘actual’ resolution doesn’t see them. I assume that’s because they’re resolved statically.

But, you know, would’ve solved my problem :slight_smile:

Thoughts?


#2

I’ve just done a reasonably large multiplatform-ization. You probably have to go with wrappers. Although if you have an external javascript library you can do some nasty things with externals (especially given how javascript works and isn’t as strict as the JVM). Unfortunately expect/actual is really strict and there are at least two issues:

  • poor support for expecting static members of classes (such as URI.create)
  • no support for function aliasses (like present for types) – inline functions go far, but not the whole way
  • If an expected class has a parent interface that is indirectly implemented through a parent in the actual class this will not work (if you specify the interface again it will create a compiler error - there are 2 superclasses; if you don’t specify it again the multiplatform code complains).

#3

I’ve refactored and sort of worked around my issues. It’s been an interesting experience. Some things work incredibly well, then you run into an incompatibility and have to unwind a large class structure and rethink.

I’m also doing this to kotlin/native and iOS, so everything is super new. It’s come along, though. Progress!