Skip to content

Commit

Permalink
[ABI Validation] Don't register companion class from const val property
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhinkin authored and qodana-bot committed Jan 3, 2025
1 parent 17b7886 commit 81a1ff7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ private fun FieldNode.buildFieldSignature(
foundAnnotations.addAll(companionClass?.visibleAnnotations.orEmpty())
foundAnnotations.addAll(companionClass?.invisibleAnnotations.orEmpty())
} else if (isStatic(access) && isFinal(access)) {
companionClass = ownerClass.companionName(ownerClass.kotlinMetadata)?.let {
val companionClassCandidate = ownerClass.companionName(ownerClass.kotlinMetadata)?.let {
classes[it]
}

val property = companionClass?.kmProperty(name)
val property = companionClassCandidate?.kmProperty(name)

if (property != null && JvmFlag.Property.IS_MOVED_FROM_INTERFACE_COMPANION(property.flags)) {
/*
Expand All @@ -140,7 +140,11 @@ private fun FieldNode.buildFieldSignature(
*
* See https://github.com/Kotlin/binary-compatibility-validator/issues/90
*/
foundAnnotations.addAll(companionClass!!.methods.annotationsFor(property.syntheticMethodForAnnotations))
foundAnnotations.addAll(
companionClassCandidate.methods.annotationsFor(
property.syntheticMethodForAnnotations
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2016-2024 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

package cases.enums

public enum class EnumWithInternalCompanion {
A, B;

internal companion object
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ public final class cases/enums/EnumClass : java/lang/Enum {
public static fun values ()[Lcases/enums/EnumClass;
}

public final class cases/enums/EnumWithInternalCompanion : java/lang/Enum {
public static final field A Lcases/enums/EnumWithInternalCompanion;
public static final field B Lcases/enums/EnumWithInternalCompanion;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public static fun valueOf (Ljava/lang/String;)Lcases/enums/EnumWithInternalCompanion;
public static fun values ()[Lcases/enums/EnumWithInternalCompanion;
}

public final class cases/enums/JavaEnum : java/lang/Enum {
public static final field JA Lcases/enums/JavaEnum;
public static final field JB Lcases/enums/JavaEnum;
Expand Down

0 comments on commit 81a1ff7

Please sign in to comment.