K2: suppress exception when reading unsupported metadata
Before the change, the compiler threw exception in the unmuted tests, because it tried to load metadata even though it had an unsupported version. Use the same approach as in K1 (see DeserializedDescriptorResolver). Now the tests are unmuted, but note that test data differs from K1. K1 does not report errors related to the class `a.A` because it loads this class as a _Java class_, so calling its constructor and methods somehow works. This behavior is questionable since the compiler surely knows that it is a Kotlin class, but with an unsupported metadata version. Trying to interpret it as a Java class may lead to subtle problems. So it's safer for now to avoid loading Kotlin classes with unsupported metadata versions in K2. #KT-60795 Fixed
This commit is contained in:
committed by
Space Team
parent
8f720ad24b
commit
8738ffb84f
+6
-4
@@ -286,8 +286,11 @@ abstract class AbstractCompileKotlinAgainstCustomBinariesTest : AbstractKotlinCo
|
||||
doTestKotlinLibraryWithWrongMetadataVersion("library", null)
|
||||
}
|
||||
|
||||
// KT-60795 K2: missing INCOMPATIBLE_CLASS and corresponding CLI error
|
||||
fun testWrongMetadataVersionBadMetadata() = muteForK2 {
|
||||
// This test compiles a library with a "future" metadata version, then intentionally inserts some gibberish to the metadata, and tries
|
||||
// to compile something against this library. It emulates the scenario when a future Kotlin version has a completely different metadata
|
||||
// format -- so different that reading it as if it's the current (protobuf-based) format would most likely result in an exception.
|
||||
// Expected result is that the compiler does NOT try to read it, and instead reports incompatible version & unresolved reference errors.
|
||||
fun testWrongMetadataVersionBadMetadata() {
|
||||
doTestKotlinLibraryWithWrongMetadataVersion("library", { name, value ->
|
||||
if (JvmAnnotationNames.METADATA_DATA_FIELD_NAME == name) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@@ -299,8 +302,7 @@ abstract class AbstractCompileKotlinAgainstCustomBinariesTest : AbstractKotlinCo
|
||||
})
|
||||
}
|
||||
|
||||
// KT-60795 K2: missing INCOMPATIBLE_CLASS and corresponding CLI error
|
||||
fun testWrongMetadataVersionBadMetadata2() = muteForK2 {
|
||||
fun testWrongMetadataVersionBadMetadata2() {
|
||||
doTestKotlinLibraryWithWrongMetadataVersion("library", { name, _ ->
|
||||
if (JvmAnnotationNames.METADATA_STRINGS_FIELD_NAME == name) arrayOf<String>() else null
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user