Skip to content

Commit

Permalink
Support Kotlin 2+ (#10)
Browse files Browse the repository at this point in the history
* Support Kotlin 2

* Upgrade junit to 4.13.2

* Resurrect embedded.gradle
  • Loading branch information
tianyu authored Jan 7, 2025
1 parent dc454f4 commit 943b392
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.8.20'
id 'org.jetbrains.kotlin.jvm' version '2.0.0'
}

allprojects {
Expand Down
2 changes: 1 addition & 1 deletion integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation project('scala-module')
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'

kotlinCompilerPluginClasspath project(':kotlin-plugin')
}
5 changes: 3 additions & 2 deletions kotlin-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin-api"
compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable"

testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.5.0'
testImplementation 'junit:junit:4.12'
// testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.5.0' does not support Kotlin 2
testImplementation 'dev.zacsweers.kctfork:core:0.6.0' // Fork of kotlin-compile-testing that supports Kotlin 2
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid

private object ObjectSerializationOrigin : IrDeclarationOriginImpl("object-serialization-fix", isSynthetic = true)
private val objectSerializationOrigin = IrDeclarationOriginImpl("object-serialization-fix", isSynthetic = true)

class ObjectSerializationIrGeneration : IrGenerationExtension {
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
Expand All @@ -37,7 +37,7 @@ class ObjectSerializationIrGeneration : IrGenerationExtension {
name = SERIALIZABLE_READ
returnType = context.irBuiltIns.anyNType
visibility = DescriptorVisibilities.PUBLIC
origin = ObjectSerializationOrigin
origin = objectSerializationOrigin
}.also { function ->
// Ensure it is not static
function.dispatchReceiverParameter = cls.thisReceiver?.copyTo(function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,13 @@ import com.tschuchort.compiletesting.SourceFile
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.runners.Parameterized.Parameters
import java.lang.reflect.Method

@OptIn(ExperimentalCompilerApi::class)
@RunWith(Parameterized::class)
class ObjectSerializationFixTest(enableIr: Boolean, enableFir: Boolean) {
companion object {
@Parameters(name = "IR: {0}, FIR: {1}")
@JvmStatic
fun data() = arrayOf(arrayOf(false, false), arrayOf(true, false), arrayOf(true, true))
}

class ObjectSerializationFixTest {
private val compiler = KotlinCompilation().apply {
compilerPluginRegistrars = listOf(ObjectSerializationCompilerPluginRegistrar())
useIR = enableIr
supportsK2 = true
useK2 = enableFir
}

private val SERIALIZABLE_OBJECT = """
Expand Down

0 comments on commit 943b392

Please sign in to comment.