https://kotlinlang.org logo
#stdlib
Title
# stdlib
f

Forrest Pangborn

01/29/2022, 3:54 PM
I believe in the past I read somewhere in official documentation that the use of
expect
+
actual
within non-multiplatform modules (or even with a single sourceset) was intentionally supported behavior, but I can't seem to find that anywhere now. does anyone know if this is still the case? everywhere I can find it on the kotlin site, it only seems to reference/encourage use of this mechanism in cases of
expect
in a common module and
actual
in platform modules. i'm looking to use it with a single common sourceset and wondering if this is something i ought to actually avoid, in case it may become unsupported.
i

ilya.gorbunov

01/30/2022, 6:40 PM
So you want to use an expect + actual declaration pair in a single source set targeted for a single platform? Why do you need it instead of just one declaration?
f

Forrest Pangborn

01/30/2022, 7:00 PM
in this case, i'm building a library that will work in combination with a ksp processor. i'm considering defining expect in common code for which the processor will generate the corresponding actual impl. the expect/actual here will serve as part of the lib's public API (or as a very proximate implementation detail). i could build things such that i generate code for each platform but that's not preferable for 2 reasons: 1. there's nothing platform-specific thats needed - so it'd be redundantly generated. 2. i'd have to explicitly define support for all platforms. as that list is probably expected to grow/change over time, that creates extra required maintenance to ensure compatibility. if the current ability for use of expect/actual within a single sourceset isn't explicitly/intentionally supported behavior (or there's a known solid chance it might be removed in the future), i'll look to go with a different approach though.
i

ilya.gorbunov

01/31/2022, 2:31 AM
Thanks. That's an interesting case somewhat similar to partial methods in C#, and it wasn't originally considered. I recommend reporting it as a feature request to https://kotl.in/issue, so that the developers of Kotlin multiplatform functionality would be aware about such use scenario.
👍 1
f

Forrest Pangborn

01/31/2022, 2:33 AM
Will do that. Does that mean what I'm doing currently is not intentionally supported in the meantime? If you also can't really answer as it's not firmly established, that's also fine :)