From 25c600c556a5524a652c160837f39761821e58e4 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 23 Jan 2023 23:13:43 +0100 Subject: [PATCH] Fix incorrect check for major version in core:metadata It affected the changed test in the following way: "strict metadata version semantics" is a flag which is written to the .kotlin_module file between the version and the protobuf data, see `ModuleMapping:73`. But flags are written only for Kotlin 1.4+, i.e. if `isKotlin1Dot4OrLater` returns true. So in the test, the flag was not written, thus we did not detect that the module actually has incompatible metadata, and thus incorrectly did not report an error. It also has an effect that version requirements for nested classes will now be written correctly to protobuf with metadata version 2.0+. --- .../strictMetadataVersionSemanticsOldVersion/output.txt | 7 +++---- .../metadata/deserialization/versionSpecificBehavior.kt | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/output.txt index d98b48619d8..dde593cbc07 100644 --- a/compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/output.txt +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/output.txt @@ -1,14 +1,13 @@ error: incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors +$TMP_DIR$/library.jar!/META-INF/main.kotlin_module: error: module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.0.0, expected version is $ABI_VERSION$. compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/source.kt:3:13: error: class 'a.C' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.0.0, but the compiler version $ABI_VERSION$ can read versions up to $ABI_VERSION$. The class is loaded from $TMP_DIR$/library.jar!/a/C.class fun test(c: C) { ^ -compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/source.kt:4:5: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.0.0, but the compiler version $ABI_VERSION$ can read versions up to $ABI_VERSION$. -The class is loaded from $TMP_DIR$/library.jar!/a/AKt.class +compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/source.kt:4:5: error: unresolved reference: f f() ^ -compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/source.kt:5:5: error: class 'a.AKt' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.0.0, but the compiler version $ABI_VERSION$ can read versions up to $ABI_VERSION$. -The class is loaded from $TMP_DIR$/library.jar!/a/AKt.class +compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/source.kt:5:5: error: unresolved reference: v v ^ compiler/testData/compileKotlinAgainstCustomBinaries/strictMetadataVersionSemanticsOldVersion/source.kt:6:5: error: class 'a.C' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.0.0, but the compiler version $ABI_VERSION$ can read versions up to $ABI_VERSION$. diff --git a/core/metadata/src/org/jetbrains/kotlin/metadata/deserialization/versionSpecificBehavior.kt b/core/metadata/src/org/jetbrains/kotlin/metadata/deserialization/versionSpecificBehavior.kt index 3ac6b424082..ec395458c1d 100644 --- a/core/metadata/src/org/jetbrains/kotlin/metadata/deserialization/versionSpecificBehavior.kt +++ b/core/metadata/src/org/jetbrains/kotlin/metadata/deserialization/versionSpecificBehavior.kt @@ -20,4 +20,4 @@ fun isVersionRequirementTableWrittenCorrectly(version: BinaryVersion): Boolean = isKotlin1Dot4OrLater(version) fun isKotlin1Dot4OrLater(version: BinaryVersion): Boolean = - version.major == 1 && version.minor >= 4 + (version.major == 1 && version.minor >= 4) || version.major > 1