kotlinx-metadata-jvm: report error on using metadata version < 1.4 in writers
The main reason for this change is that the current API for class version requirements (`KmClass.versionRequirements`) makes it impossible to support pre-1.4 metadata where this was stored incorrectly for nested classes: with the "version requirement table" in the outer class, and indexes into that table in nested classes. See KT-41011. Other than this aspect, metadata of classes is basically the same in pre-1.4 and 1.4, which means that if some kotlinx-metadata-jvm users really need to serialize metadata of an earlier version and they don't care about the version requirements issue, they can just use these new bytes but write the earlier version (e.g. 1.1) to the class file. Everything will work the same, except for the possible version requirements issue mentioned above. Note that metadata version 1.4 is still supported for `KotlinModuleMetadata.Writer` though. #KT-41011 Fixed
This commit is contained in:
+5
-7
@@ -12,14 +12,12 @@ package org.jetbrains.kotlin.metadata.deserialization
|
||||
// fix the bug in serialization when the binary version advances to the value supported in the first bug fix.
|
||||
|
||||
/**
|
||||
* Before Kotlin 1.4, version requirements for nested classes were deserialized incorrectly: the version requirement table was loaded from
|
||||
* the outermost class and passed to the nested classes and their members, even though indices of their version requirements were pointing
|
||||
* to the other table stored in the nested class (which was not read by deserialization). See KT-25120 for more information
|
||||
* Before metadata version 1.4, version requirements for nested classes were deserialized incorrectly: the version requirement table was
|
||||
* loaded from the outermost class and passed to the nested classes and their members, even though indices of their version requirements
|
||||
* were pointing to the other table stored in the nested class (which was not read by deserialization). See KT-25120 for more information.
|
||||
*/
|
||||
fun isVersionRequirementTableWrittenCorrectly(version: BinaryVersion): Boolean =
|
||||
isKotlin1Dot4OrLater(version)
|
||||
|
||||
fun isKotlin1Dot4OrLater(version: BinaryVersion): Boolean {
|
||||
// All metadata versions (JVM, JS, common) will be advanced to 1.4.0 in Kotlin 1.4
|
||||
return version.major == 1 && version.minor >= 4
|
||||
}
|
||||
fun isKotlin1Dot4OrLater(version: BinaryVersion): Boolean =
|
||||
version.major == 1 && version.minor >= 4
|
||||
|
||||
Reference in New Issue
Block a user