From d757847ed6a8f923e413858cde29addc11028eef Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 3 May 2023 11:48:41 +0200 Subject: [PATCH] JVM: enable -Xlambdas=class for some backend tests These tests are checking the specifics of the class-generated lambdas. --- .../checkLocalVariablesTable/destructuringInLambdas.kt | 2 ++ .../testData/checkLocalVariablesTable/itInLambda.kt | 2 ++ .../checkLocalVariablesTable/itInReturnedLambda.kt | 2 ++ .../testData/checkLocalVariablesTable/lambdaAsVar.kt | 2 ++ .../objectInLocalPropertyDelegate.kt | 2 ++ .../checkLocalVariablesTable/underscoreNames.kt | 2 ++ .../syntheticAccessorForPropertiesSignatureClash.args | 1 + .../syntheticAccessorPropertyAndFunSignatureClash.args | 1 + .../box/jvm8/defaults/noDefaultImpls/kt11969.kt | 1 + compiler/testData/writeFlags/lambda/simpleLambda.kt | 2 ++ .../protectedAccessToBaseMethodDifferentPackage.kt | 1 + .../writeSignature/syntheticAccessorForGeneric.kt | 2 ++ .../tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt | 10 ++++++++-- .../testData/parcel/box/functions.kt | 1 + .../parcelize-compiler/testData/box/functions.kt | 3 ++- .../parcelize-compiler/testData/box/typeParameters.kt | 1 + 16 files changed, 32 insertions(+), 3 deletions(-) diff --git a/compiler/testData/checkLocalVariablesTable/destructuringInLambdas.kt b/compiler/testData/checkLocalVariablesTable/destructuringInLambdas.kt index fe226f80728..027813abd1f 100644 --- a/compiler/testData/checkLocalVariablesTable/destructuringInLambdas.kt +++ b/compiler/testData/checkLocalVariablesTable/destructuringInLambdas.kt @@ -1,3 +1,5 @@ +// LAMBDAS: CLASS + data class A(val x: String, val y: Int) fun foo(a: A, block: (A) -> String): String = block(a) diff --git a/compiler/testData/checkLocalVariablesTable/itInLambda.kt b/compiler/testData/checkLocalVariablesTable/itInLambda.kt index 359fccf3e96..d770fab078f 100644 --- a/compiler/testData/checkLocalVariablesTable/itInLambda.kt +++ b/compiler/testData/checkLocalVariablesTable/itInLambda.kt @@ -1,3 +1,5 @@ +// LAMBDAS: CLASS + public fun Iterable.myforEach(operation: (T) -> Unit) : Unit { for (element in this) operation(element) } diff --git a/compiler/testData/checkLocalVariablesTable/itInReturnedLambda.kt b/compiler/testData/checkLocalVariablesTable/itInReturnedLambda.kt index e69b36b2a8a..dd3809ddebf 100644 --- a/compiler/testData/checkLocalVariablesTable/itInReturnedLambda.kt +++ b/compiler/testData/checkLocalVariablesTable/itInReturnedLambda.kt @@ -1,3 +1,5 @@ +// LAMBDAS: CLASS + fun foo() { fun bar() : (Int) -> Unit { return { diff --git a/compiler/testData/checkLocalVariablesTable/lambdaAsVar.kt b/compiler/testData/checkLocalVariablesTable/lambdaAsVar.kt index e562031bbd9..692856ca0b9 100644 --- a/compiler/testData/checkLocalVariablesTable/lambdaAsVar.kt +++ b/compiler/testData/checkLocalVariablesTable/lambdaAsVar.kt @@ -1,3 +1,5 @@ +// LAMBDAS: CLASS + fun foo() { var a = { diff --git a/compiler/testData/checkLocalVariablesTable/objectInLocalPropertyDelegate.kt b/compiler/testData/checkLocalVariablesTable/objectInLocalPropertyDelegate.kt index 2308e6e15b2..3e0f6e6713c 100644 --- a/compiler/testData/checkLocalVariablesTable/objectInLocalPropertyDelegate.kt +++ b/compiler/testData/checkLocalVariablesTable/objectInLocalPropertyDelegate.kt @@ -1,3 +1,5 @@ +// LAMBDAS: CLASS + operator fun (() -> String).getValue(thisRef: Any?, property: Any?) = this() fun foo() { diff --git a/compiler/testData/checkLocalVariablesTable/underscoreNames.kt b/compiler/testData/checkLocalVariablesTable/underscoreNames.kt index 3ee2514b9f1..e14ea6ec6eb 100644 --- a/compiler/testData/checkLocalVariablesTable/underscoreNames.kt +++ b/compiler/testData/checkLocalVariablesTable/underscoreNames.kt @@ -1,3 +1,5 @@ +// LAMBDAS: CLASS + data class A(val x: Double = 1.0, val y: String = "", val z: Char = '0') fun foo(a: A, block: (A, String, Int) -> String): String = block(a, "", 1) diff --git a/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.args b/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.args index 2fa85939740..3482f68b94b 100644 --- a/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.args +++ b/compiler/testData/cli/jvm/syntheticAccessorForPropertiesSignatureClash.args @@ -1,3 +1,4 @@ $TESTDATA_DIR$/syntheticAccessorForPropertiesSignatureClash.kt -d $TEMP_DIR$ +-Xlambdas=class diff --git a/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.args b/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.args index 540b43a0373..a05be913b7b 100644 --- a/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.args +++ b/compiler/testData/cli/jvm/syntheticAccessorPropertyAndFunSignatureClash.args @@ -1,3 +1,4 @@ $TESTDATA_DIR$/syntheticAccessorPropertyAndFunSignatureClash.kt -d $TEMP_DIR$ +-Xlambdas=class diff --git a/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt11969.kt b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt11969.kt index 2461dd15157..aa09c5f9754 100644 --- a/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt11969.kt +++ b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/kt11969.kt @@ -3,6 +3,7 @@ // IGNORE_BACKEND: ANDROID // JVM_TARGET: 1.8 // WITH_STDLIB +// LAMBDAS: CLASS interface Z { private fun privateFun() = { "OK" } diff --git a/compiler/testData/writeFlags/lambda/simpleLambda.kt b/compiler/testData/writeFlags/lambda/simpleLambda.kt index eea052bd0b9..f2e431abf39 100644 --- a/compiler/testData/writeFlags/lambda/simpleLambda.kt +++ b/compiler/testData/writeFlags/lambda/simpleLambda.kt @@ -1,3 +1,5 @@ +// LAMBDAS: CLASS + class Foo { fun foo() = { } } diff --git a/compiler/testData/writeFlags/protectedAccessToBaseMethodDifferentPackage.kt b/compiler/testData/writeFlags/protectedAccessToBaseMethodDifferentPackage.kt index a09996db4fa..51b341bf638 100644 --- a/compiler/testData/writeFlags/protectedAccessToBaseMethodDifferentPackage.kt +++ b/compiler/testData/writeFlags/protectedAccessToBaseMethodDifferentPackage.kt @@ -1,3 +1,4 @@ +// LAMBDAS: CLASS // IGNORE_BACKEND_K2: JVM_IR // TARGET_BACKEND: JVM // FILE: Base.java diff --git a/compiler/testData/writeSignature/syntheticAccessorForGeneric.kt b/compiler/testData/writeSignature/syntheticAccessorForGeneric.kt index 32a5720cd60..c84ec6bb26c 100644 --- a/compiler/testData/writeSignature/syntheticAccessorForGeneric.kt +++ b/compiler/testData/writeSignature/syntheticAccessorForGeneric.kt @@ -1,3 +1,5 @@ +// LAMBDAS: CLASS + class MyList { private fun noSignature(): T? = null diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt index e5770265237..c37c0855b26 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt @@ -9,7 +9,6 @@ import org.jetbrains.kotlin.checkers.ENABLE_JVM_PREVIEW import org.jetbrains.kotlin.checkers.parseLanguageVersionSettings import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.config.* -import org.jetbrains.kotlin.config.JvmTarget.Companion.fromString import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase import org.jetbrains.kotlin.test.util.KtTestUtil import java.io.File @@ -147,7 +146,7 @@ abstract class KotlinBaseTest : KtUsefulTestCase() } val targetString = directives["JVM_TARGET"] if (targetString != null) { - val jvmTarget = fromString(targetString) + val jvmTarget = JvmTarget.fromString(targetString) ?: error("Unknown target: $targetString") configuration.put(JVMConfigurationKeys.JVM_TARGET, jvmTarget) } @@ -173,6 +172,13 @@ abstract class KotlinBaseTest : KtUsefulTestCase() assert(explicitLanguageVersionSettings == null) { "Should not specify !LANGUAGE directive twice" } explicitLanguageVersionSettings = fileLanguageVersionSettings } + + val lambdasString = directives["LAMBDAS"] + if (lambdasString != null) { + val lambdas = JvmClosureGenerationScheme.fromString(lambdasString) + ?: error("Unknown lambdas mode: $lambdasString") + configuration.put(JVMConfigurationKeys.LAMBDAS, lambdas) + } } if (explicitLanguageVersionSettings != null) { configuration.languageVersionSettings = explicitLanguageVersionSettings diff --git a/plugins/android-extensions/android-extensions-compiler/testData/parcel/box/functions.kt b/plugins/android-extensions/android-extensions-compiler/testData/parcel/box/functions.kt index 141536c037c..20290b48acd 100644 --- a/plugins/android-extensions/android-extensions-compiler/testData/parcel/box/functions.kt +++ b/plugins/android-extensions/android-extensions-compiler/testData/parcel/box/functions.kt @@ -1,4 +1,5 @@ // WITH_STDLIB +// LAMBDAS: CLASS @file:JvmName("TestKt") package test diff --git a/plugins/parcelize/parcelize-compiler/testData/box/functions.kt b/plugins/parcelize/parcelize-compiler/testData/box/functions.kt index 893bd1550a3..b7ca8afc4bf 100644 --- a/plugins/parcelize/parcelize-compiler/testData/box/functions.kt +++ b/plugins/parcelize/parcelize-compiler/testData/box/functions.kt @@ -1,4 +1,5 @@ // WITH_STDLIB +// LAMBDAS: CLASS @file:JvmName("TestKt") package test @@ -21,4 +22,4 @@ fun box() = parcelTest { parcel -> parcelableCreator().createFromParcel(parcel) assert(test.callback() == 1) -} \ No newline at end of file +} diff --git a/plugins/parcelize/parcelize-compiler/testData/box/typeParameters.kt b/plugins/parcelize/parcelize-compiler/testData/box/typeParameters.kt index 66ab1e3a639..007546f1c00 100644 --- a/plugins/parcelize/parcelize-compiler/testData/box/typeParameters.kt +++ b/plugins/parcelize/parcelize-compiler/testData/box/typeParameters.kt @@ -1,5 +1,6 @@ // See KT-44891, https://issuetracker.google.com/180193969 // WITH_STDLIB +// LAMBDAS: CLASS @file:JvmName("TestKt") package test