diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/Constructor.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/Constructor.txt index 08fac34a63c..5e2ea3bb313 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/Constructor.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/Constructor.txt @@ -7,6 +7,6 @@ public final annotation class Anno : R|kotlin/Annotation| { } public final class Constructor : R|kotlin/Any| { - public constructor(): R|test/Constructor| + @R|test/Anno|(value = String(string)) public constructor(): R|test/Constructor| } diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/HiddenConstructorWithInlineClassParameters.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/HiddenConstructorWithInlineClassParameters.txt index bebbcbecfc8..4e1ea6759d2 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/HiddenConstructorWithInlineClassParameters.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/HiddenConstructorWithInlineClassParameters.txt @@ -7,7 +7,7 @@ public sealed class Sealed : R|kotlin/Any| { public final val z: R|test/Z| public get(): R|test/Z| - private constructor(z: R|test/Z|): R|test/Sealed| + @R|test/Ann|() private constructor(z: R|test/Z|): R|test/Sealed| public final class Derived : R|test/Sealed| { public constructor(z: R|test/Z|): R|test/Sealed.Derived| @@ -20,11 +20,11 @@ public final class Test : R|kotlin/Any| { public final val z: R|test/Z| public get(): R|test/Z| - public constructor(z: R|test/Z|, a: R|kotlin/Int|): R|test/Test| + @R|test/Ann|() public constructor(z: R|test/Z|, a: R|kotlin/Int|): R|test/Test| - private constructor(z: R|test/Z|, s: R|kotlin/String|): R|test/Test| + @R|test/Ann|() private constructor(z: R|test/Z|, s: R|kotlin/String|): R|test/Test| - public constructor(z: R|test/Z|): R|test/Test| + @R|test/Ann|() public constructor(z: R|test/Z|): R|test/Test| } diff --git a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/PublishedApiAnnotationOnInlineClassCosntructor.txt b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/PublishedApiAnnotationOnInlineClassCosntructor.txt index 76349b9c3a5..01998465158 100644 --- a/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/PublishedApiAnnotationOnInlineClassCosntructor.txt +++ b/compiler/fir/analysis-tests/testData/loadCompiledKotlin/annotations/classMembers/PublishedApiAnnotationOnInlineClassCosntructor.txt @@ -8,6 +8,6 @@ public final inline class Z : R|kotlin/Any| { public final val value: R|kotlin/Int| public get(): R|kotlin/Int| - internal constructor(value: R|kotlin/Int|): R|test/Z| + @R|kotlin/PublishedApi|() internal constructor(value: R|kotlin/Int|): R|test/Z| } diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt index 4d0db9d8eb3..ae8f299dd59 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/deserialization/JvmBinaryAnnotationDeserializer.kt @@ -45,6 +45,16 @@ class JvmBinaryAnnotationDeserializer( return annotations.map { deserializeAnnotation(it, nameResolver) } } + override fun loadConstructorAnnotations( + containerSource: DeserializedContainerSource?, + constructorProto: ProtoBuf.Constructor, + nameResolver: NameResolver, + typeTable: TypeTable + ): List { + val signature = getCallableSignature(constructorProto, nameResolver, typeTable, CallableKind.FUNCTION) ?: return emptyList() + return findJvmBinaryClassAndLoadMemberAnnotations(containerSource, signature) + } + override fun loadFunctionAnnotations( containerSource: DeserializedContainerSource?, functionProto: ProtoBuf.Function, @@ -84,7 +94,11 @@ class JvmBinaryAnnotationDeserializer( kind: CallableKind ): MemberSignature? { return when (proto) { - // TODO: ProtoBuf.Constructor + is ProtoBuf.Constructor -> { + MemberSignature.fromJvmMemberSignature( + JvmProtoBufUtil.getJvmConstructorSignature(proto, nameResolver, typeTable) ?: return null + ) + } is ProtoBuf.Function -> { val signature = JvmProtoBufUtil.getJvmMethodSignature(proto, nameResolver, typeTable) ?: return null // TODO: Investigate why annotations for accessors affect resolution, resulting in dangling type parameter. diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt index 7758f0cb1bf..b0dcf1eac18 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/AbstractAnnotationDeserializer.kt @@ -87,7 +87,12 @@ abstract class AbstractAnnotationDeserializer( return annotations.map { deserializeAnnotation(it, nameResolver) } } - fun loadConstructorAnnotations(constructorProto: ProtoBuf.Constructor, nameResolver: NameResolver): List { + open fun loadConstructorAnnotations( + containerSource: DeserializedContainerSource?, + constructorProto: ProtoBuf.Constructor, + nameResolver: NameResolver, + typeTable: TypeTable + ): List { if (!Flags.HAS_ANNOTATIONS.get(constructorProto.flags)) return emptyList() val annotations = constructorProto.getExtension(protocol.constructorAnnotation).orEmpty() return annotations.map { deserializeAnnotation(it, nameResolver) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt index b0d87c768d4..c8bf06e597d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt @@ -371,7 +371,8 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { valueParameters += local.memberDeserializer.valueParameters( proto.valueParameterList, addDefaultValue = classBuilder.symbol.classId == StandardClassIds.Enum ) - annotations += local.annotationDeserializer.loadConstructorAnnotations(proto, local.nameResolver) + annotations += + c.annotationDeserializer.loadConstructorAnnotations(c.containerSource, proto, local.nameResolver, local.typeTable) }.build() }