diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck/library/a.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck/library/a.kt new file mode 100644 index 00000000000..a311bb96854 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck/library/a.kt @@ -0,0 +1,9 @@ +package a + +open class A { + class Nested +} + +fun foo() {} +var bar = 42 +typealias TA = String diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck/output.txt new file mode 100644 index 00000000000..a0aba9318ad --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck/output.txt @@ -0,0 +1 @@ +OK \ No newline at end of file diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck/source.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck/source.kt new file mode 100644 index 00000000000..6f6e9ef8209 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck/source.kt @@ -0,0 +1,15 @@ +@file:Suppress("UNUSED_VARIABLE") +package usage + +import a.* + +fun baz(param: A) { + val constructor = A() + val methodCall = param.hashCode() + val supertype = object : A() {} + + val x = foo() + val y = bar + bar = 239 + val z: TA = "" +} diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.java index dc89eef1cdd..c17039bbe1a 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.java @@ -316,12 +316,12 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir { KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output)); } - @SuppressWarnings("deprecation") private void doTestPreReleaseKotlinLibrary( @NotNull CLICompiler compiler, @NotNull String libraryName, @NotNull File destination, @NotNull File result, + @NotNull File usageDestination, @NotNull String... additionalOptions ) throws Exception { // Compiles the library with the "pre-release" flag, then compiles a usage of this library in the release mode @@ -337,7 +337,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir { Pair output; try { System.setProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY, "false"); - output = compileKotlin(compiler, "source.kt", tmpdir, Arrays.asList(additionalOptions), result); + output = compileKotlin(compiler, "source.kt", usageDestination, Arrays.asList(additionalOptions), result); } finally { System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY); @@ -459,19 +459,33 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir { public void testReleaseCompilerAgainstPreReleaseLibrary() throws Exception { File destination = new File(tmpdir, "library.jar"); - doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination); + doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination, tmpdir); } public void testReleaseCompilerAgainstPreReleaseLibraryJs() throws Exception { - doTestPreReleaseKotlinLibrary(new K2JSCompiler(), "library", - new File(tmpdir, "library.js"), - new File(tmpdir, "library.meta.js")); + doTestPreReleaseKotlinLibrary( + new K2JSCompiler(), "library", + new File(tmpdir, "library.js"), new File(tmpdir, "library.meta.js"), + new File(tmpdir, "usage.js") + ); } public void testReleaseCompilerAgainstPreReleaseLibrarySkipVersionCheck() throws Exception { File destination = new File(tmpdir, "library.jar"); - doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination, - "-Xskip-metadata-version-check"); + doTestPreReleaseKotlinLibrary( + new K2JVMCompiler(), "library", + destination, destination, tmpdir, + "-Xskip-metadata-version-check" + ); + } + + public void testReleaseCompilerAgainstPreReleaseLibraryJsSkipVersionCheck() throws Exception { + doTestPreReleaseKotlinLibrary( + new K2JSCompiler(), "library", + new File(tmpdir, "library.js"), new File(tmpdir, "library.meta.js"), + new File(tmpdir, "usage.js"), + "-Xskip-metadata-version-check" + ); } public void testWrongMetadataVersion() throws Exception { diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptPackageFragment.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptPackageFragment.kt index 81c416fc7f9..3257b25b2b7 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptPackageFragment.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/KotlinJavascriptPackageFragment.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.serialization.ProtoBuf import org.jetbrains.kotlin.serialization.deserialization.AnnotationDeserializer +import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragmentImpl import org.jetbrains.kotlin.serialization.deserialization.IncompatibleVersionErrorData import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor @@ -40,8 +41,9 @@ class KotlinJavascriptPackageFragment( storageManager: StorageManager, module: ModuleDescriptor, proto: ProtoBuf.PackageFragment, - header: JsProtoBuf.Header -) : DeserializedPackageFragmentImpl(fqName, storageManager, module, proto, JsContainerSource(fqName, header)) { + header: JsProtoBuf.Header, + configuration: DeserializationConfiguration +) : DeserializedPackageFragmentImpl(fqName, storageManager, module, proto, JsContainerSource(fqName, header, configuration)) { private val fileMap: Map by storageManager.createLazyValue { this.proto.getExtension(JsProtoBuf.packageFragmentFiles).fileList.withIndex().associate { (index, file) -> (if (file.hasId()) file.id else index) to FileHolder(file.annotationList) @@ -72,7 +74,11 @@ class KotlinJavascriptPackageFragment( } } - private class JsContainerSource(private val fqName: FqName, private val header: JsProtoBuf.Header) : DeserializedContainerSource { + private class JsContainerSource( + private val fqName: FqName, + header: JsProtoBuf.Header, + configuration: DeserializationConfiguration + ) : DeserializedContainerSource { // TODO override fun getContainingFile(): SourceFile = SourceFile.NO_SOURCE_FILE @@ -81,10 +87,9 @@ class KotlinJavascriptPackageFragment( override val incompatibility: IncompatibleVersionErrorData<*>? get() = null - override val isPreReleaseInvisible: Boolean - get() = (header.flags and 1) != 0 && !KotlinCompilerVersion.isPreRelease() + override val isPreReleaseInvisible: Boolean = + !configuration.skipMetadataVersionCheck && (header.flags and 1) != 0 && !KotlinCompilerVersion.isPreRelease() - // TODO: this is not a class override val presentableString: String get() = "Package '$fqName'" } diff --git a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/kotlinJavascriptPackageFragmentProvider.kt b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/kotlinJavascriptPackageFragmentProvider.kt index 1822ff95f95..12d41f32719 100644 --- a/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/kotlinJavascriptPackageFragmentProvider.kt +++ b/js/js.serializer/src/org/jetbrains/kotlin/serialization/js/kotlinJavascriptPackageFragmentProvider.kt @@ -34,7 +34,7 @@ fun createKotlinJavascriptPackageFragmentProvider( ): PackageFragmentProvider { val packageFragments = packageFragmentProtos.mapNotNull { proto -> proto.fqName?.let { fqName -> - KotlinJavascriptPackageFragment(fqName, storageManager, module, proto, header) + KotlinJavascriptPackageFragment(fqName, storageManager, module, proto, header, configuration) } }