A small proposal, currently on Kotlin Multiplatfor...
# multiplatform
f
A small proposal, currently on Kotlin Multiplatform if someone wants to define value classes one has to use @JvmInline annotation on jvm sourcesets and not use it on non-jvm sourcesets which creates an unnecessary platform sourceset split since the code could otherwise be platform agnostic. Since it is an annotation to indicate to the JVM backend to use a specific opitimazation other targets (Kotlin/JS and Kotlin/Native) could just ignore it without throwing an error. (Treat it as a no-op on non-jvm backends) Filed on YouTrack: https://youtrack.jetbrains.com/issue/KT-53404/Treat-JvmInline-annotations-as-no-op-on-non-jvm-backends-for-better-Multiplatform-experience Example on playground: https://pl.kotl.in/R4XMcQfCJ
Copy code
// ^ Try different backends
// v And commenting out or not
// @JvmInline
value class NonEmptyString(val value: String) {
    init {
        require(value.isNotEmpty())
    }
}

fun main() {
    println(NonEmptyString("Hello"))
    try {
        println(NonEmptyString(""))
    } catch(e: Throwable) {
        println("Woops!")
    }
}
Slack Conversation
m
I just gave your example a try. After adding the proper import statement
Copy code
import kotlin.jvm.JvmInline
your code compiles and runs just fine on iOS and on JS where it should not be runnable according to your statements.