[JVM IR] Fix lambdaInLocalFunction.kt by adding helper methods that
return the target backend under test.
This commit is contained in:
committed by
Alexander Udalov
parent
beb3165839
commit
7329a1641a
+12
-5
@@ -1,8 +1,10 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
// WITH_HELPERS
|
||||
|
||||
import helpers.*
|
||||
|
||||
fun box(): String {
|
||||
fun foo(): Any {
|
||||
@@ -10,11 +12,16 @@ fun box(): String {
|
||||
}
|
||||
|
||||
val javaClass = foo().javaClass
|
||||
val enclosingMethod = javaClass.getEnclosingMethod()
|
||||
if (enclosingMethod?.getName() != "invoke") return "method: $enclosingMethod"
|
||||
|
||||
val enclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
if (enclosingClass != "LambdaInLocalFunctionKt\$box$1") return "enclosing class: $enclosingClass"
|
||||
// The enclosing method is a local function, which are in a separate class (implementing FunctionN) for non-IR, and are static methods
|
||||
// in the enclosing class for IR.
|
||||
val actualEnclosingMethod = javaClass.getEnclosingMethod()!!.getName()
|
||||
val expectedEnclosingMethod = if (isIR()) "box\$foo" else "invoke"
|
||||
if (actualEnclosingMethod != expectedEnclosingMethod) return "method: $actualEnclosingMethod"
|
||||
|
||||
val actualEnclosingClass = javaClass.getEnclosingClass()!!.getName()
|
||||
val expectedEnclosingClass = if (isIR()) "LambdaInLocalFunctionKt" else "LambdaInLocalFunctionKt\$box\$1"
|
||||
if (actualEnclosingClass != expectedEnclosingClass) return "enclosing class: $actualEnclosingClass"
|
||||
|
||||
val declaringClass = javaClass.getDeclaringClass()
|
||||
if (declaringClass != null) return "anonymous function has a declaring class: $declaringClass"
|
||||
|
||||
+11
-1
@@ -6,8 +6,10 @@
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
|
||||
fun createTextForHelpers(isReleaseCoroutines: Boolean, checkStateMachine: Boolean, checkTailCallOptimization: Boolean): String {
|
||||
// Add the directive `// WITH_COROUTINES` to use these helpers in codegen tests (see TestFiles.java).
|
||||
fun createTextForCoroutineHelpers(isReleaseCoroutines: Boolean, checkStateMachine: Boolean, checkTailCallOptimization: Boolean): String {
|
||||
val coroutinesPackage =
|
||||
if (isReleaseCoroutines)
|
||||
DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE.asString()
|
||||
@@ -188,3 +190,11 @@ fun createTextForHelpers(isReleaseCoroutines: Boolean, checkStateMachine: Boolea
|
||||
|${if (checkTailCallOptimization) checkTailCallOptimizationString else ""}
|
||||
""".trimMargin()
|
||||
}
|
||||
|
||||
// Add the directive `// WITH_HELPERS` to use these helpers in codegen tests (see CodegenTestCase.java).
|
||||
fun createTextForCodegenTestHelpers(backend: TargetBackend) =
|
||||
"""
|
||||
|package helpers
|
||||
|
|
||||
|fun isIR() = ${backend.isIR}
|
||||
""".trimMargin()
|
||||
@@ -16,6 +16,7 @@ import kotlin.io.FilesKt;
|
||||
import kotlin.text.Charsets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.TestHelperGeneratorKt;
|
||||
import org.jetbrains.kotlin.TestsCompilerError;
|
||||
import org.jetbrains.kotlin.TestsCompiletimeError;
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||
@@ -783,7 +784,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
expectedText = expectedText.replace("COROUTINES_PACKAGE", coroutinesPackage);
|
||||
}
|
||||
|
||||
List<TestFile> testFiles = createTestFiles(file, expectedText, coroutinesPackage);
|
||||
List<TestFile> testFiles = createTestFiles(file, expectedText);
|
||||
|
||||
doMultiFileTest(file, testFiles);
|
||||
}
|
||||
@@ -794,14 +795,18 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<TestFile> createTestFiles(File file, String expectedText, String coroutinesPackage) {
|
||||
return TestFiles.createTestFiles(file.getName(), expectedText, new TestFiles.TestFileFactoryNoModules<TestFile>() {
|
||||
private List<TestFile> createTestFiles(File file, String expectedText) {
|
||||
List testFiles = TestFiles.createTestFiles(file.getName(), expectedText, new TestFiles.TestFileFactoryNoModules<TestFile>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public TestFile create(@NotNull String fileName, @NotNull String text, @NotNull Map<String, String> directives) {
|
||||
return new TestFile(fileName, text);
|
||||
}
|
||||
}, coroutinesPackage);
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(expectedText, "WITH_HELPERS")) {
|
||||
testFiles.add(new TestFile("CodegenTestHelpers.kt", TestHelperGeneratorKt.createTextForCodegenTestHelpers(getBackend())));
|
||||
}
|
||||
return testFiles;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.test;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.CoroutineTestUtilKt;
|
||||
import org.jetbrains.kotlin.TestHelperGeneratorKt;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -113,7 +113,8 @@ public class TestFiles {
|
||||
factory.createFile(
|
||||
supportModule,
|
||||
"CoroutineUtil.kt",
|
||||
CoroutineTestUtilKt.createTextForHelpers(isReleaseCoroutines, checkStateMachine, checkTailCallOptimization),
|
||||
TestHelperGeneratorKt.createTextForCoroutineHelpers(
|
||||
isReleaseCoroutines, checkStateMachine, checkTailCallOptimization),
|
||||
directives
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user