diff --git a/compiler/testData/codegen/box/delegation/byMiddleInterface.kt b/compiler/testData/codegen/box/delegation/byMiddleInterface.kt index 5f6256df741..f4e61e75afa 100644 --- a/compiler/testData/codegen/box/delegation/byMiddleInterface.kt +++ b/compiler/testData/codegen/box/delegation/byMiddleInterface.kt @@ -1,6 +1,4 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM - // FILE: Base.java public interface Base { @@ -12,6 +10,7 @@ public interface Base { } // FILE: main.kt +// JVM_TARGET: 1.8 public interface BaseKotlin : Base { } diff --git a/compiler/testData/codegen/box/delegation/defaultOverride.kt b/compiler/testData/codegen/box/delegation/defaultOverride.kt index c2a66177a7a..25bdbf7a7f2 100644 --- a/compiler/testData/codegen/box/delegation/defaultOverride.kt +++ b/compiler/testData/codegen/box/delegation/defaultOverride.kt @@ -1,6 +1,4 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM - // FILE: Base.java public interface Base { @@ -12,6 +10,7 @@ public interface Base { } // FILE: main.kt +// JVM_TARGET: 1.8 public interface BaseKotlin : Base { override fun getValue() = "OK" diff --git a/compiler/testData/codegen/box/delegation/diamond.kt b/compiler/testData/codegen/box/delegation/diamond.kt index 8a60bda7ef8..7a539ee55bf 100644 --- a/compiler/testData/codegen/box/delegation/diamond.kt +++ b/compiler/testData/codegen/box/delegation/diamond.kt @@ -1,4 +1,3 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM // FILE: Base.java @@ -18,8 +17,8 @@ public interface Base2 extends Base { } } - // FILE: main.kt +// JVM_TARGET: 1.8 interface KBase : Base diff --git a/compiler/testData/codegen/box/delegation/diamond2.kt b/compiler/testData/codegen/box/delegation/diamond2.kt index daf19245ade..251670895cc 100644 --- a/compiler/testData/codegen/box/delegation/diamond2.kt +++ b/compiler/testData/codegen/box/delegation/diamond2.kt @@ -1,4 +1,3 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM // FILE: Base.java @@ -18,6 +17,7 @@ public interface Base2 extends Base { // FILE: main.kt +// JVM_TARGET: 1.8 interface KBase : Base { override fun test() = "O" + getValue() diff --git a/compiler/testData/codegen/box/delegation/inClassDeclaration.kt b/compiler/testData/codegen/box/delegation/inClassDeclaration.kt index 57d180b8c38..e29eea6a650 100644 --- a/compiler/testData/codegen/box/delegation/inClassDeclaration.kt +++ b/compiler/testData/codegen/box/delegation/inClassDeclaration.kt @@ -1,4 +1,3 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM // FILE: Base.java @@ -11,6 +10,8 @@ public interface Base { } // FILE: main.kt +// JVM_TARGET: 1.8 + class Fail : Base { override fun getValue() = "Fail" } diff --git a/compiler/testData/codegen/box/delegation/mixed.kt b/compiler/testData/codegen/box/delegation/mixed.kt index c8ef7c370a8..091fdbfd6e3 100644 --- a/compiler/testData/codegen/box/delegation/mixed.kt +++ b/compiler/testData/codegen/box/delegation/mixed.kt @@ -1,4 +1,3 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM // FILE: Base.java @@ -11,6 +10,8 @@ public interface Base extends KBase { } // FILE: main.kt +// JVM_TARGET: 1.8 + interface KBase { fun getValue(): String diff --git a/compiler/testData/codegen/box/delegation/simple.kt b/compiler/testData/codegen/box/delegation/simple.kt index 418cea053e1..2f176b6a473 100644 --- a/compiler/testData/codegen/box/delegation/simple.kt +++ b/compiler/testData/codegen/box/delegation/simple.kt @@ -1,4 +1,3 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM // FILE: Base.java @@ -11,6 +10,8 @@ public interface Base { } // FILE: main.kt +// JVM_TARGET: 1.8 + class Fail : Base { override fun getValue() = "Fail" } diff --git a/compiler/testData/codegen/box/delegation/simple1.0.kt b/compiler/testData/codegen/box/delegation/simple1.0.kt index 7395fca1c61..7d22a09f9ed 100644 --- a/compiler/testData/codegen/box/delegation/simple1.0.kt +++ b/compiler/testData/codegen/box/delegation/simple1.0.kt @@ -1,6 +1,5 @@ // !LANGUAGE: -NoDelegationToJavaDefaultInterfaceMembers // IGNORE_BACKEND_FIR: JVM_IR -// SKIP_JDK6 // TARGET_BACKEND: JVM // FILE: Base.java @@ -13,6 +12,8 @@ public interface Base { } // FILE: main.kt +// JVM_TARGET: 1.8 + class OK : Base { override fun getValue() = "OK" } diff --git a/compiler/testData/codegen/box/javaInterop/notNullAssertions/enhancedNullability/inFunctionWithExpressionBodyWithJavaGeneric.kt b/compiler/testData/codegen/box/javaInterop/notNullAssertions/enhancedNullability/inFunctionWithExpressionBodyWithJavaGeneric.kt index e85957c8e19..b979afffc2e 100644 --- a/compiler/testData/codegen/box/javaInterop/notNullAssertions/enhancedNullability/inFunctionWithExpressionBodyWithJavaGeneric.kt +++ b/compiler/testData/codegen/box/javaInterop/notNullAssertions/enhancedNullability/inFunctionWithExpressionBodyWithJavaGeneric.kt @@ -1,6 +1,5 @@ // !LANGUAGE: +StrictJavaNullabilityAssertions // TARGET_BACKEND: JVM -// SKIP_JDK6 // See KT-8135 // We could generate runtime assertion on call site for 'generic()' below. @@ -24,11 +23,12 @@ fun generic(j: J) = j.nullT() import org.jetbrains.annotations.NotNull; public class J { - public @NotNull T nullT() { + @NotNull + public T nullT() { return null; } public void test() { TestKt.withAssertion(this); } -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/jvm8/javaDefaults/defaultMethodOverride.kt b/compiler/testData/codegen/box/jvm8/javaDefaults/defaultMethodOverride.kt index 287f7458c32..6deb9b3d6e9 100644 --- a/compiler/testData/codegen/box/jvm8/javaDefaults/defaultMethodOverride.kt +++ b/compiler/testData/codegen/box/jvm8/javaDefaults/defaultMethodOverride.kt @@ -1,4 +1,3 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM // FILE: Simple.java @@ -9,6 +8,7 @@ public interface Simple { } // FILE: main.kt +// JVM_TARGET: 1.8 interface KInterface: Simple { override fun test(s: String): String { diff --git a/compiler/testData/codegen/box/jvm8/javaDefaults/dontDelegateToDefaultMethods.kt b/compiler/testData/codegen/box/jvm8/javaDefaults/dontDelegateToDefaultMethods.kt index 148aaf82fed..b1d313c5b4b 100644 --- a/compiler/testData/codegen/box/jvm8/javaDefaults/dontDelegateToDefaultMethods.kt +++ b/compiler/testData/codegen/box/jvm8/javaDefaults/dontDelegateToDefaultMethods.kt @@ -1,4 +1,3 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM // FILE: Test.java @@ -12,6 +11,7 @@ interface Test { } // FILE: main.kt +// JVM_TARGET: 1.8 class Child : Test { override fun call() : String { diff --git a/compiler/testData/codegen/box/jvm8/javaDefaults/samOnInterfaceWithDefaultMethod.kt b/compiler/testData/codegen/box/jvm8/javaDefaults/samOnInterfaceWithDefaultMethod.kt index a69fb2b71df..9afd98732b1 100644 --- a/compiler/testData/codegen/box/jvm8/javaDefaults/samOnInterfaceWithDefaultMethod.kt +++ b/compiler/testData/codegen/box/jvm8/javaDefaults/samOnInterfaceWithDefaultMethod.kt @@ -1,4 +1,3 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM // FILE: JavaCall.java @@ -24,6 +23,7 @@ interface Test { } // FILE: sam.kt +// JVM_TARGET: 1.8 fun box(): String { val lambda = { "X" } diff --git a/compiler/testData/codegen/box/smartCasts/kt19058.kt b/compiler/testData/codegen/box/smartCasts/kt19058.kt index 1f558682449..8f92195d0f2 100644 --- a/compiler/testData/codegen/box/smartCasts/kt19058.kt +++ b/compiler/testData/codegen/box/smartCasts/kt19058.kt @@ -1,5 +1,5 @@ -// SKIP_JDK6 // TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 // FILE: Test.kt open class KFoo { fun foo(): String { @@ -17,4 +17,4 @@ public interface JBar { default String getBar() { return "OK"; } -} \ No newline at end of file +} diff --git a/compiler/testData/codegen/box/traits/multipleImplFromJava.kt b/compiler/testData/codegen/box/traits/multipleImplFromJava.kt index 748dceeecb8..276f901456f 100644 --- a/compiler/testData/codegen/box/traits/multipleImplFromJava.kt +++ b/compiler/testData/codegen/box/traits/multipleImplFromJava.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM -// SKIP_JDK6 // FILE: I.java interface I { default String ifun() { return "fail"; } @@ -14,6 +13,7 @@ public class Z { public class Zz extends Z implements I {} // FILE: multipleImplFromJava.kt +// JVM_TARGET: 1.8 class Cc : Zz() diff --git a/compiler/testData/codegen/bytecodeListing/kt43217.kt b/compiler/testData/codegen/bytecodeListing/kt43217.kt index a62b2547b78..966f20378c3 100644 --- a/compiler/testData/codegen/bytecodeListing/kt43217.kt +++ b/compiler/testData/codegen/bytecodeListing/kt43217.kt @@ -1,4 +1,5 @@ // FILE: kt43217.kt +// JVM_TARGET: 1.8 class A { private val b = object : DoubleExpression() { @@ -43,4 +44,3 @@ public interface ObservableDouble extends ObservableValue { @NotNull Object isEqualTo(double value); } - diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt index b45162d67e1..e7805127728 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractBlackBoxAgainstJavaCodegenTest.kt @@ -18,12 +18,17 @@ package org.jetbrains.kotlin.codegen import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.config.JvmTarget import java.io.File abstract class AbstractBlackBoxAgainstJavaCodegenTest : AbstractBlackBoxCodegenTest() { override fun doMultiFileTest(wholeFile: File, files: List) { javaClassesOutputDirectory = writeJavaFiles(files)!!.let { directory -> - CodegenTestUtil.compileJava(CodegenTestUtil.findJavaSourcesInDirectory(directory), emptyList(), extractJavacOptions(files)) + val jvmTargets = files.mapNotNullTo(mutableSetOf()) { it.directives["JVM_TARGET"]?.let((JvmTarget)::fromString) } + check(jvmTargets.size <= 1) { "Having different JVM_TARGETs for different files is not supported in this test." } + CodegenTestUtil.compileJava( + CodegenTestUtil.findJavaSourcesInDirectory(directory), emptyList(), extractJavacOptions(files, jvmTargets.firstOrNull()) + ) } super.doMultiFileTest(wholeFile, files.map { file -> diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java index 5e1fddd142e..9debd333195 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java @@ -63,9 +63,7 @@ import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo; import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*; import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls; import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar; -import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getBoxMethodOrNull; -import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGeneratedClass; -import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.runBoxMethod; +import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.*; public abstract class CodegenTestCase extends KotlinBaseTest { private static final String DEFAULT_TEST_FILE_NAME = "a_test"; @@ -487,7 +485,6 @@ public abstract class CodegenTestCase extends KotlinBaseTest InTextDirectivesUtils.isDirectiveDefined(it.content, "ANDROID_ANNOTATIONS") ); - List javacOptions = extractJavacOptions(files); List classpath = new ArrayList<>(); classpath.add(getAnnotationsJar()); @@ -531,6 +528,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest javacOptions = extractJavacOptions(files, configuration.get(JVMConfigurationKeys.JVM_TARGET)); compileJava(findJavaSourcesInDirectory(javaSourceDir), javaClasspath, javacOptions, javaClassesOutputDirectory); } } @@ -538,22 +536,33 @@ public abstract class CodegenTestCase extends KotlinBaseTest javaClasspath) {} @NotNull - protected static List extractJavacOptions(@NotNull List files) { + protected static List extractJavacOptions(@NotNull List files, @Nullable JvmTarget kotlinTarget) { List javacOptions = new ArrayList<>(0); for (TestFile file : files) { javacOptions.addAll(InTextDirectivesUtils.findListWithPrefixes(file.content, "// JAVAC_OPTIONS:")); } - updateJavacOptions(javacOptions); + String javaTarget = computeJavaTarget(javacOptions, kotlinTarget); + if (javaTarget != null) { + javacOptions.add("-source"); + javacOptions.add(javaTarget); + javacOptions.add("-target"); + javacOptions.add(javaTarget); + } return javacOptions; } - private static void updateJavacOptions(@NotNull List javacOptions) { - if (JAVA_COMPILATION_TARGET != null && !javacOptions.contains("-target")) { - javacOptions.add("-source"); - javacOptions.add(JAVA_COMPILATION_TARGET); - javacOptions.add("-target"); - javacOptions.add(JAVA_COMPILATION_TARGET); - } + private static final boolean IS_SOURCE_6_STILL_SUPPORTED = + // JDKs up to 11 do support -source/target 1.6, but later -- don't. + Arrays.asList("1.6", "1.7", "1.8", "9", "10", "11").contains(System.getProperty("java.specification.version")); + + private static String computeJavaTarget(@NotNull List javacOptions, @Nullable JvmTarget kotlinTarget) { + if (JAVA_COMPILATION_TARGET != null && !javacOptions.contains("-target")) + return JAVA_COMPILATION_TARGET; + if (kotlinTarget != null && kotlinTarget.compareTo(JvmTarget.JVM_1_6) > 0) + return kotlinTarget.getDescription(); + if (IS_SOURCE_6_STILL_SUPPORTED) + return "1.6"; + return null; } @NotNull