[K2/N] Fix property accessors modality in K2 metadata
^KT-56603
This commit is contained in:
committed by
Space Team
parent
aa3c189d83
commit
b01cc1f88c
+2
-1
@@ -929,7 +929,8 @@ class FirElementSerializer private constructor(
|
|||||||
return Flags.getAccessorFlags(
|
return Flags.getAccessorFlags(
|
||||||
nonSourceAnnotations.isNotEmpty(),
|
nonSourceAnnotations.isNotEmpty(),
|
||||||
ProtoEnumFlags.visibility(normalizeVisibility(accessor)),
|
ProtoEnumFlags.visibility(normalizeVisibility(accessor)),
|
||||||
ProtoEnumFlags.modality(accessor.modality!!),
|
// non-default accessor modality is always final, so we check property.modality instead
|
||||||
|
ProtoEnumFlags.modality(property.modality!!),
|
||||||
!isDefault,
|
!isDefault,
|
||||||
accessor.isExternal,
|
accessor.isExternal,
|
||||||
accessor.isInline
|
accessor.isInline
|
||||||
|
|||||||
+6
-2
@@ -79,18 +79,22 @@ class DeclarationPrinter(
|
|||||||
|
|
||||||
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, data: Unit) {
|
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, data: Unit) {
|
||||||
printer.printPlain(header = headerRenderer.render(descriptor), signature = signatureRenderer.render(descriptor))
|
printer.printPlain(header = headerRenderer.render(descriptor), signature = signatureRenderer.render(descriptor))
|
||||||
descriptor.getter?.takeIf { !it.annotations.isEmpty() }?.let { getter ->
|
descriptor.getter?.takeUnless { canSkipAccessor(it, descriptor) }?.let { getter ->
|
||||||
printer.pushIndent()
|
printer.pushIndent()
|
||||||
printer.printPlain(header = headerRenderer.render(getter), signature = signatureRenderer.render(getter))
|
printer.printPlain(header = headerRenderer.render(getter), signature = signatureRenderer.render(getter))
|
||||||
printer.popIndent()
|
printer.popIndent()
|
||||||
}
|
}
|
||||||
descriptor.setter?.takeIf { !it.annotations.isEmpty() || it.visibility != descriptor.visibility }?.let { setter ->
|
descriptor.setter?.takeUnless { canSkipAccessor(it, descriptor) }?.let { setter ->
|
||||||
printer.pushIndent()
|
printer.pushIndent()
|
||||||
printer.printPlain(header = headerRenderer.render(setter), signature = signatureRenderer.render(setter))
|
printer.printPlain(header = headerRenderer.render(setter), signature = signatureRenderer.render(setter))
|
||||||
printer.popIndent()
|
printer.popIndent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun canSkipAccessor(accessor: PropertyAccessorDescriptor, property: PropertyDescriptor) : Boolean {
|
||||||
|
return accessor.annotations.isEmpty() && accessor.visibility == property.visibility && accessor.modality == property.modality
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor, data: Unit) {
|
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor, data: Unit) {
|
||||||
printer.printPlain(header = headerRenderer.render(descriptor), signature = signatureRenderer.render(descriptor))
|
printer.printPlain(header = headerRenderer.render(descriptor), signature = signatureRenderer.render(descriptor))
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -48,6 +48,9 @@ object DefaultDeclarationHeaderRenderer : DeclarationHeaderRenderer {
|
|||||||
if (descriptor.visibility != DescriptorVisibilities.DEFAULT_VISIBILITY) {
|
if (descriptor.visibility != DescriptorVisibilities.DEFAULT_VISIBILITY) {
|
||||||
append(descriptor.visibility.internalDisplayName).append(" ")
|
append(descriptor.visibility.internalDisplayName).append(" ")
|
||||||
}
|
}
|
||||||
|
if (descriptor.modality != descriptor.correspondingProperty.modality) {
|
||||||
|
append(descriptor.modality.name.lowercase()).append(" ")
|
||||||
|
}
|
||||||
when (descriptor) {
|
when (descriptor) {
|
||||||
is PropertyGetterDescriptor -> append("get")
|
is PropertyGetterDescriptor -> append("get")
|
||||||
is PropertySetterDescriptor -> append("set")
|
is PropertySetterDescriptor -> append("set")
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
abstract class A {
|
||||||
|
abstract val a: Int
|
||||||
|
abstract var b: Int
|
||||||
|
protected set
|
||||||
|
val c: Int = TODO()
|
||||||
|
val d: Int
|
||||||
|
get() = TODO()
|
||||||
|
var e: Int
|
||||||
|
get() = TODO()
|
||||||
|
set(value) = TODO()
|
||||||
|
var f: Int = TODO()
|
||||||
|
private set
|
||||||
|
open val g: Int = TODO()
|
||||||
|
open val h: Int
|
||||||
|
get() = TODO()
|
||||||
|
open var k: Int
|
||||||
|
get() = TODO()
|
||||||
|
set(value) = TODO()
|
||||||
|
open var l: Int = TODO()
|
||||||
|
protected set
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
abstract class A constructor() {
|
||||||
|
abstract val a: Int
|
||||||
|
abstract var b: Int
|
||||||
|
protected set
|
||||||
|
val c: Int
|
||||||
|
val d: Int
|
||||||
|
var e: Int
|
||||||
|
var f: Int
|
||||||
|
private set
|
||||||
|
open val g: Int
|
||||||
|
open val h: Int
|
||||||
|
open var k: Int
|
||||||
|
open var l: Int
|
||||||
|
protected set
|
||||||
|
}
|
||||||
+6
@@ -53,6 +53,12 @@ public class FirNativeKLibContentsTestGenerated extends AbstractNativeKlibConten
|
|||||||
runTest("native/native.tests/testData/klibContents/kt56018_value_parameters_annotations.kt");
|
runTest("native/native.tests/testData/klibContents/kt56018_value_parameters_annotations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("property_accessors.kt")
|
||||||
|
public void testProperty_accessors() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/klibContents/property_accessors.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("type_annotations.kt")
|
@TestMetadata("type_annotations.kt")
|
||||||
public void testType_annotations() throws Exception {
|
public void testType_annotations() throws Exception {
|
||||||
|
|||||||
+6
@@ -50,6 +50,12 @@ public class K1NativeKLibContentsTestGenerated extends AbstractNativeKlibContent
|
|||||||
runTest("native/native.tests/testData/klibContents/kt56018_value_parameters_annotations.kt");
|
runTest("native/native.tests/testData/klibContents/kt56018_value_parameters_annotations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("property_accessors.kt")
|
||||||
|
public void testProperty_accessors() throws Exception {
|
||||||
|
runTest("native/native.tests/testData/klibContents/property_accessors.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("type_annotations.kt")
|
@TestMetadata("type_annotations.kt")
|
||||||
public void testType_annotations() throws Exception {
|
public void testType_annotations() throws Exception {
|
||||||
|
|||||||
+2
-4
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.konan.blackboxtest.support.runner.*
|
|||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
|
import org.jetbrains.kotlin.konan.blackboxtest.support.settings.*
|
||||||
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
|
import org.jetbrains.kotlin.konan.blackboxtest.support.util.*
|
||||||
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals
|
||||||
|
import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEqualsToFile
|
||||||
import org.junit.jupiter.api.Tag
|
import org.junit.jupiter.api.Tag
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -31,10 +32,7 @@ abstract class AbstractNativeKlibContentsTest : AbstractNativeSimpleTest() {
|
|||||||
val kotlinNativeClassLoader = testRunSettings.get<KotlinNativeClassLoader>()
|
val kotlinNativeClassLoader = testRunSettings.get<KotlinNativeClassLoader>()
|
||||||
val klibContents = testCompilationResult.assertSuccess().resultingArtifact.getContents(kotlinNativeClassLoader.classLoader)
|
val klibContents = testCompilationResult.assertSuccess().resultingArtifact.getContents(kotlinNativeClassLoader.classLoader)
|
||||||
val klibContentsFiltered = filterContentsOutput(klibContents, linestoExclude = listOf("package test {", "}", ""))
|
val klibContentsFiltered = filterContentsOutput(klibContents, linestoExclude = listOf("package test {", "}", ""))
|
||||||
val expectedContents = File("${testPathFull.canonicalPath.substringBeforeLast(".")}.txt").readText()
|
assertEqualsToFile(File("${testPathFull.canonicalPath.substringBeforeLast(".")}.txt"), StringUtilRt.convertLineSeparators(klibContentsFiltered))
|
||||||
assertEquals(StringUtilRt.convertLineSeparators(expectedContents), StringUtilRt.convertLineSeparators(klibContentsFiltered)) {
|
|
||||||
"Test failed. Compilation result was: $testCompilationResult"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateTestCaseWithSingleSource(source: File, extraArgs: List<String>): TestCase {
|
private fun generateTestCaseWithSingleSource(source: File, extraArgs: List<String>): TestCase {
|
||||||
|
|||||||
Reference in New Issue
Block a user