https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
p

pajatopmr

11/27/2018, 11:49 AM
I have a project targeting JVM and Native where I want to “expect” a File and then typealias the actual but I am beginning to think this might not be possible. How might I accomplish my goal of using the name “File” in both common and JVM code?
t

thevery

11/27/2018, 12:17 PM
actual typealias File = java.io.File
?
p

pajatopmr

11/27/2018, 12:27 PM
Tried that, no joy. I saw that @kpgalligan tried something similar with no joy as well and worked around the issue so I followed his lead, fwiw.
i

ilya.gorbunov

11/27/2018, 1:11 PM
What problems have you struggled with? Something with mapping expect properties to Java getters?
o

olonho

11/27/2018, 7:15 PM
What do you want to typealias File on Native to?
k

kpgalligan

11/27/2018, 7:16 PM
Hey, missed this thread. Sorry.
The issue with typealias depends on what you're defining in the expect class
If you're defining a method that is protected in Java, it won't work, even though it seems like it should. There's a bug filed for this that's been outstanding for a while. It'll take a bit to dig up...
p

pajatopmr

11/27/2018, 7:18 PM
I want the native code for Win/Lin/Mac to use a posix file type, CValuePointer or some such if memory serves as the aliased type, .e.g. actual alias File = CValuePointer
The expect declaration is “expect typealias File”
k

kpgalligan

11/27/2018, 7:19 PM
The expect is typealias? Didn't know that was a thing.
p

pajatopmr

11/27/2018, 7:20 PM
It might not be. 🙂
But it seemed like a good idea at the time.
k

kpgalligan

11/27/2018, 7:22 PM
For the record, the visibility issue is here: https://youtrack.jetbrains.net/issue/KT-19848
That's not the issue you're having.
You'd need to define what the 'File' object should do in expect, then implement in actual. That implementation might point to posix, but you need to implement it. You can have a single 'native' implementation, but all target platforms would need to have access to the posix file api
I'm not proud of this, but I did a copypasta for quick and dirty file ops in knarch: https://github.com/touchlab/knarch.db/tree/master/kotlin/knarch-ios/src/main/kotlin/co/touchlab/knarch/io
A more adult local file library would be super cool. Happy to provide some support if you're building that 🙂
p

pajatopmr

11/27/2018, 7:29 PM
Yes, I hope I am. Thanks for the link.
k

kpgalligan

11/27/2018, 7:30 PM
Ah. That was so long ago. I was delegating to posix.Forgot
Just a heads up. The file/folder listing calls bomb (I think, at least sometimes)
p

pajatopmr

11/27/2018, 9:11 PM
For the JetBrains @olonho folks, is “expect typealias Foo” a thing or wishful thinking on my part?
I think I now understand: one would use “expect class File” and realize this for JVM by “actual typealias File = java.io.File”
👌 1
o

olonho

11/28/2018, 5:18 AM
Yes, expect typealias shall work, but POSIX file APIs provide different level of abstraction compared to
java.io.File
, just typealiasing will unlikely be helpful here