Kotlin / binary-compatibility-validator

Public API management tool
Apache License 2.0
788 stars 57 forks source link

[0.15.0] Enum entries are not part of generated `.api` dump anymore if the enum contains internal companion object #250

Closed mateuszkwiecinski closed 1 month ago

mateuszkwiecinski commented 1 month ago

For a given class:

package com.luciad.imageio.webp

public enum class CompressionType(internal val imageIoValue: String) {
    Lossy("Lossy"),
    Lossless("Lossless"),
    ;

    internal companion object {

        val imageIoCompressionTypes = entries.map { it.imageIoValue }.toTypedArray()
    }
}

Migration from 0.14.0 to 0.15.0 produces the following build failure:

Execution failed for task ':webp-imageio:apiCheck'.
> API check failed for project webp-imageio.
  --- /home/runner/work/webp-imageio/webp-imageio/webp-imageio/api/webp-imageio.api
  +++ /home/runner/work/webp-imageio/webp-imageio/webp-imageio/build/api/webp-imageio.api
  @@ -1,6 +1,4 @@
   public final class com/luciad/imageio/webp/CompressionType : java/lang/Enum {
  - public static final field Lossless Lcom/luciad/imageio/webp/CompressionType;
  - public static final field Lossy Lcom/luciad/imageio/webp/CompressionType;
    public static fun getEntries ()Lkotlin/enums/EnumEntries;
    public static fun valueOf (Ljava/lang/String;)Lcom/luciad/imageio/webp/CompressionType;
    public static fun values ()[Lcom/luciad/imageio/webp/CompressionType;

Running apiDump generates dump without enum entries.

Expected result: Enum entries are part of api dump

This happened in: https://github.com/usefulness/webp-imageio/pull/212 - a project with no custom config. I can try to come up with simpler repro if needed 👀 I checked release notes, but this is not a multiplatform project, it doesn't have any custom config, the file name name did not change and is all-lowercase

It seems like the dump is generated properly if I remove or make the companion object public

fzhinkin commented 1 month ago

@mateuszkwiecinski thanks for reporting the issue!

It seems to be a regression introduced after https://github.com/Kotlin/binary-compatibility-validator/pull/245 was merged.