Skip to content

Commit

Permalink
Add Kotlin 1.9 compatibility tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timaliberdov committed Jan 10, 2024
1 parent 3637504 commit d711eab
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sbt-test/kotlin/kotlin-1.9-compat/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import kotlin.Keys._

enablePlugins(KotlinPlugin)
kotlinLib("stdlib")

kotlinVersion := "1.9.20"
kotlincJvmTarget := "1.8"

val listClasses = taskKey[Unit]("listClasses")

listClasses := {
val classes = (Compile / classDirectory).value.listFiles()
streams.value.log.info("classes: " + classes.mkString("Array(", ", ", ")"))
}
6 changes: 6 additions & 0 deletions src/sbt-test/kotlin/kotlin-1.9-compat/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sys.props.get("plugin.version") match {
case Some(version) => addSbtPlugin("org.jetbrains.scala" % "sbt-kotlin-plugin" % version)
case _ => sys.error(
"""The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -Dplugin.version.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This script is not supposed to be inside source root. Since Kotlin 1.9 it is ignored during the module compilation.
// See https://youtrack.jetbrains.com/issue/KT-52735
println("Hello world!")
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package demo

fun main(args: Array<String>) {
// Test some Kotlin 1.9 features
println(findByRgb("#FF0000"))
println(Person("John", "Doe"))
}

enum class Color(val colorName: String, val rgb: String) {
RED("Red", "#FF0000"),
ORANGE("Orange", "#FF7F00"),
YELLOW("Yellow", "#FFFF00")
}

// In 1.8.20, the entries property for enum classes was introduced as an Experimental feature.
// The entries property is a modern and performant replacement for the synthetic values() function.
// In 1.9.0, the entries property is Stable.
fun findByRgb(rgb: String): Color? = Color.entries.find { it.rgb == rgb }

@JvmInline
value class Person(private val fullName: String) {
// Allowed since Kotlin 1.4.30:
init {
check(fullName.isNotBlank()) {
"Full name shouldn't be empty"
}
}
// Allowed by default since Kotlin 1.9.0:
constructor(name: String, lastName: String) : this("$name $lastName") {
check(lastName.isNotBlank()) {
"Last name shouldn't be empty"
}
}
}
4 changes: 4 additions & 0 deletions src/sbt-test/kotlin/kotlin-1.9-compat/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> compile
> listClasses
$ exists target/scala-2.12/classes/demo/SimpleKt.class
$ absent target/scala-2.12/classes/SimpleScript.class

0 comments on commit d711eab

Please sign in to comment.