Skip to content

Fix #2364 - distinguish enum qualifiers by declaring type - #2487

Open
djain2405 wants to merge 1 commit into
InsertKoinIO:mainfrom
djain2405:fix/2364-enum-qualifier-collision
Open

djain2405 wants to merge 1 commit into
InsertKoinIO:mainfrom
djain2405:fix/2364-enum-qualifier-collision

Conversation

@djain2405

Copy link
Copy Markdown

Fixes #2364

  • Enum qualifiers used only the lowercased constant name, so two enums with the same constant shared one key and Koin could return the wrong instance. This showed up in production after R8 renamed constants in different enums to the same string.
  • Enum.qualifier is now simpleName.name, lowercased. named(Names1.ENUM_NAME) is names1.enum_name instead of enum_name. KClass.qualifiedName is not used because it does not compile on Kotlin/JS.
  • Declaring and resolving with the same enum still works: single(named(NetworkClient.ENCRYPTED)) / get(named(NetworkClient.ENCRYPTED)). A string qualifier no longer matches that enum: named("encrypted") is not named(NetworkClient.ENCRYPTED).
  • No public signature change. apiCheck passes and no .api dump update is needed.
    Please note on https://insert-koin.io/docs/reference/koin-core/qualifiers that an enum qualifier value now includes the enum type. docs/ in this repo was left unchanged.

@djain2405

djain2405 commented Nov 11, 2026 •

Copy link
Copy Markdown
Author

@arnaudgiuliani 🙇

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum<E>.qualifier now uses "$typeName.$name" with this::class.simpleName; two enums in different packages with the same simple class name and constant still collide (foo.Mode.ON and bar.Mode.ON both become mode.on). Could the qualifier include a stable multiplatform type identity, with a regression for same-named enums in different packages?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Named qualifiers from enums with identically named values are equal

2 participants