Skip to content

Support Kotlin 2+ #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove this comment

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
Comment on lines -24 to -26
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kotlin 2 has deprecated IR, so the forked K2 version of kotlin-compile-testing has taken that option away. I decided to make this test not parameterized since, going forward, useIR will always be false and useK2 will always be true.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still want to test with enableFir flag since technically some people could compile with language version 1.9

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, dev.zacsweers.kctfork:core:0.6.0, which is a fork of com.github.tschuchortdev:kotlin-compile-testing:1.5.0 does not support the useIR and useK2 properties...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should support languageVersion, which is technically the same (you want 1.9 for k1 or 2.0+ for k2)

}

private val SERIALIZABLE_OBJECT = """
Expand Down
Loading