Do not return field signature if there's none in the metadata
Otherwise this code behaves incorrectly on getter-only properties: it returns a meaningless field signature whereas the property has no field. It's hard to come up with an example of when this could matter in compiler code, but it's very noticeable in kotlinx-metadata-jvm #KT-26188 Fixed
This commit is contained in:
+4
-5
@@ -104,13 +104,12 @@ object JvmProtoBufUtil {
|
||||
typeTable: TypeTable
|
||||
): JvmMemberSignature.Field? {
|
||||
val signature = proto.getExtensionOrNull(JvmProtoBuf.propertySignature) ?: return null
|
||||
val field =
|
||||
if (signature.hasField()) signature.field else null
|
||||
val field = if (signature.hasField()) signature.field else return null
|
||||
|
||||
val name = if (field != null && field.hasName()) field.name else proto.name
|
||||
val name = if (field.hasName()) field.name else proto.name
|
||||
val desc =
|
||||
if (field != null && field.hasDesc()) nameResolver.getString(field.desc)
|
||||
else mapTypeDefault(proto.returnType(typeTable), nameResolver) ?: return null
|
||||
if (field.hasDesc()) nameResolver.getString(field.desc)
|
||||
else mapTypeDefault(proto.returnType(typeTable), nameResolver) ?: return null
|
||||
|
||||
return JvmMemberSignature.Field(nameResolver.getString(name), desc)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
- [`KT-25920`](https://youtrack.jetbrains.com/issue/KT-25920) Compile kotlinx-metadata-jvm with JVM target bytecode version 1.6 instead of 1.8
|
||||
- [`KT-25223`](https://youtrack.jetbrains.com/issue/KT-25223) Add JvmFunctionExtensionVisitor.visitEnd
|
||||
- [`KT-26188`](https://youtrack.jetbrains.com/issue/KT-26188) Do not pass field signature for accessor-only properties
|
||||
|
||||
## 0.0.3
|
||||
|
||||
|
||||
+5
@@ -64,6 +64,11 @@ public class KotlinpTestGenerated extends AbstractKotlinpTest {
|
||||
runTest("libraries/tools/kotlinp/testData/PlatformType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Properties.kt")
|
||||
public void testProperties() throws Exception {
|
||||
runTest("libraries/tools/kotlinp/testData/Properties.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("SimpleClass.kt")
|
||||
public void testSimpleClass() throws Exception {
|
||||
runTest("libraries/tools/kotlinp/testData/SimpleClass.kt");
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
class C(val constructorParam: String = "") {
|
||||
val getterOnlyVal: Double get() = 0.0
|
||||
var accessorOnlyVar: Int
|
||||
get() = 1
|
||||
set(value) {}
|
||||
|
||||
var withBackingField: String = "42"
|
||||
|
||||
val <T : Number> T.delegated: List<Nothing> by null
|
||||
|
||||
operator fun Nothing?.getValue(x: Any?, y: Any?) = emptyList<Nothing>()
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// C.class
|
||||
// ------------------------------------------
|
||||
public final class C : kotlin/Any {
|
||||
|
||||
// signature: <init>(Ljava/lang/String;)V
|
||||
public /* primary */ constructor(constructorParam: kotlin/String /* = ... */)
|
||||
|
||||
// signature: getValue(Ljava/lang/Void;Ljava/lang/Object;Ljava/lang/Object;)Ljava/util/List;
|
||||
public final operator fun kotlin/Nothing?.getValue(x: kotlin/Any?, y: kotlin/Any?): kotlin/collections/List<kotlin/Nothing>
|
||||
|
||||
// getter: getAccessorOnlyVar()I
|
||||
// setter: setAccessorOnlyVar(I)V
|
||||
public final var accessorOnlyVar: kotlin/Int
|
||||
public final /* non-default */ get
|
||||
public final /* non-default */ set(value: kotlin/Int)
|
||||
|
||||
// field: constructorParam:Ljava/lang/String;
|
||||
// getter: getConstructorParam()Ljava/lang/String;
|
||||
public final val constructorParam: kotlin/String
|
||||
public final get
|
||||
|
||||
// getter: getGetterOnlyVal()D
|
||||
public final val getterOnlyVal: kotlin/Double
|
||||
public final /* non-default */ get
|
||||
|
||||
// field: withBackingField:Ljava/lang/String;
|
||||
// getter: getWithBackingField()Ljava/lang/String;
|
||||
// setter: setWithBackingField(Ljava/lang/String;)V
|
||||
public final var withBackingField: kotlin/String
|
||||
public final get
|
||||
public final set
|
||||
|
||||
// field: delegated$delegate:Ljava/lang/Void;
|
||||
// getter: getDelegated(Ljava/lang/Number;)Ljava/util/List;
|
||||
public final /* delegated */ val <T#0 /* T */ : kotlin/Number> T#0.delegated: kotlin/collections/List<kotlin/Nothing>
|
||||
public final /* non-default */ get
|
||||
}
|
||||
// META-INF/test-module.kotlin_module
|
||||
// ------------------------------------------
|
||||
module {
|
||||
}
|
||||
Reference in New Issue
Block a user