After looking over the available documentation it seems like the best practice (compiler mandate?) for multiplatform projects is to mirror the package structure of the common module in the platform specific modules. But it doesn’t seem to be possible to have top level functions in files of the same name with same package structure in the common module and jvm module.
Here is a practical use case, kotlin has ulp extension property for Doubles on all platforms but for floats it only has ulp extension property on jvm platform. So if I want to make a floating point equality approximation function that works with Double in common module and one that works with Float in jvm module I have to put these functions in files with different names. So I could have com.example.project.Numbers
in common with this:
fun Double.feq(comparate: Double, maxUlps: Int): Boolean {
...
}
And com.example.project.Numbers
in jvm with this:
fun Float.feq(comparate: Double, maxUlps: Int): Boolean {
...
}
Each of these files has other utility functions as well. Right now I have to change the name of the Numbers
file in jvm module to something like NumbersJvm
This is just an example but when I was thinking about moving a codebase over the multiplatform I thought of several scenarios where I would want to have a structure like this. Is there a solution to this or is it just mandatory to not share file names between common and platform modules when the file contains top level functions or properties?